File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ Mixed.prototype.__proto__ = SchemaType.prototype;
4747 */
4848
4949Mixed . prototype . checkRequired = function ( val ) {
50- return true ;
50+ return ( val !== undefined ) && ( val !== null ) ;
5151} ;
5252
5353/**
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments