Skip to content

Commit 858b0fa

Browse files
committed
test: fix tests
1 parent bde97c1 commit 858b0fa

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/schema.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,9 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
17391739
'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
17401740
}
17411741

1742-
obj.parentSchema = this;
1742+
if (name === 'Union') {
1743+
obj.parentSchema = this;
1744+
}
17431745
const schemaType = new MongooseTypes[name](path, obj, options);
17441746

17451747
if (schemaType.$isSchemaMap) {

lib/schema/union.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
* ignore
55
*/
66

7-
const MongooseMap = require('../types/map');
87
const SchemaUnionOptions = require('../options/schemaUnionOptions');
98
const SchemaType = require('../schemaType');
10-
const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeDefinition');
119

1210
const firstValueSymbol = Symbol('firstValue');
1311

@@ -16,7 +14,7 @@ const firstValueSymbol = Symbol('firstValue');
1614
*/
1715

1816
class Union extends SchemaType {
19-
constructor(key, options, schemaOptions) {
17+
constructor(key, options, schemaOptions = {}) {
2018
super(key, options, 'Union');
2119
if (!options || !Array.isArray(options.of) || options.of.length === 0) {
2220
throw new Error('Union schema type requires an array of types');

test/schematype.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ describe('schematype', function() {
266266
});
267267

268268
const typesToTest = Object.values(mongoose.SchemaTypes).
269-
filter(t => t.name !== 'SchemaSubdocument' && t.name !== 'SchemaDocumentArray');
269+
filter(t => t.name !== 'SchemaSubdocument' && t.name !== 'SchemaDocumentArray' && t.name !== 'Union');
270270

271271
typesToTest.forEach((type) => {
272272
it(type.name + ', when given a default option, set its', () => {

0 commit comments

Comments
 (0)