Skip to content

Commit 79dc6b2

Browse files
committed
Merge pull request #1722 from kingsquare/master
Implemented checkRequired for SchemaType Mixed
2 parents 34f1c8e + c565729 commit 79dc6b2

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/schema/mixed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Mixed.prototype.__proto__ = SchemaType.prototype;
4747
*/
4848

4949
Mixed.prototype.checkRequired = function (val) {
50-
return true;
50+
return (val !== undefined) && (val !== null);
5151
};
5252

5353
/**

test/schema.validation.test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,31 @@ describe('schema', function(){
283283
});
284284
done();
285285
});
286+
287+
it('mixed required', function(done){
288+
var Animal = new Schema({
289+
characteristics: { type: Mixed, required: true }
290+
});
291+
292+
Animal.path('characteristics').doValidate(null, function(err){
293+
assert.ok(err instanceof ValidatorError);
294+
});
295+
296+
Animal.path('characteristics').doValidate(undefined, function(err){
297+
assert.ok(err instanceof ValidatorError);
298+
});
299+
300+
Animal.path('characteristics').doValidate({
301+
aggresive: true
302+
}, function(err){
303+
assert.ifError(err);
304+
});
305+
306+
Animal.path('characteristics').doValidate('none available', function(err){
307+
assert.ifError(err);
308+
});
309+
done();
310+
})
286311
})
287312

288313
describe('async', function(){
@@ -332,8 +357,8 @@ describe('schema', function(){
332357
{
333358
'validator': validator,
334359
'msg': 'validator2'
335-
},
336-
],
360+
}
361+
]
337362
}
338363
});
339364

0 commit comments

Comments
 (0)