@@ -905,13 +905,15 @@ describe('Validator', function () {
905
905
id : 1 ,
906
906
name : 'wayne'
907
907
} ;
908
+ data . $wayne = '123' ;
908
909
909
910
var result = val . validate ( data , schemaForTest , { unknownProperties : 'delete' } ) ;
910
911
911
912
expect ( result . valid ) . toBe ( true ) ;
912
913
expect ( result . errors . length ) . toBe ( 0 ) ;
913
914
expect ( data . someUnknownProperty ) . toBeUndefined ( ) ;
914
915
expect ( data . someUnknownObject ) . toBeUndefined ( ) ;
916
+ expect ( data . $wayne ) . toBeUndefined ( ) ;
915
917
} ) ;
916
918
917
919
it ( 'validate() should override the default validation options with the current options' , function ( ) {
@@ -1395,6 +1397,69 @@ describe('Validator', function () {
1395
1397
expect ( result . errors . length ) . toBe ( 2 ) ;
1396
1398
} ) ;
1397
1399
1400
+ it ( 'should return a validation error when the option "ignoreNullValues" is enabled but the property is required' , function ( ) {
1401
+ var schema = {
1402
+ properties : {
1403
+ name : {
1404
+ type : 'string' ,
1405
+ required : true
1406
+ } ,
1407
+ names : {
1408
+ type : 'array' ,
1409
+ required : true ,
1410
+ items : {
1411
+ type : 'number'
1412
+ }
1413
+ } ,
1414
+ arr : {
1415
+ type : 'array' ,
1416
+ items : {
1417
+ type : 'object' ,
1418
+ properties : {
1419
+ name : {
1420
+ type : 'string'
1421
+ } ,
1422
+ name1 : {
1423
+ type : 'boolean'
1424
+ }
1425
+ }
1426
+ }
1427
+ }
1428
+ }
1429
+ } ,
1430
+ data = {
1431
+ name : null ,
1432
+ names : null
1433
+ } ;
1434
+
1435
+ var result = val . validate ( data , schema ) ;
1436
+
1437
+ expect ( result . valid ) . toBeFalsy ( ) ;
1438
+ expect ( result . errors . length ) . toBe ( 2 ) ;
1439
+
1440
+ result = val . validate ( data , schema , { ignoreNullValues : true } ) ;
1441
+
1442
+ expect ( result . valid ) . toBeFalsy ( ) ;
1443
+ expect ( result . errors . length ) . toBe ( 2 ) ;
1444
+
1445
+ data . name = undefined ;
1446
+ result = val . validate ( data , schema , { ignoreNullValues : true } ) ;
1447
+
1448
+ expect ( result . valid ) . toBeFalsy ( ) ;
1449
+
1450
+ data . name = 'wayne' ;
1451
+ data . names = [ 1 ] ;
1452
+ data . arr = [ { name : 'test' , name1 : true } , null , { name : 'test1' , name1 : false } ] ;
1453
+ result = val . validate ( data , schema , { ignoreNullValues : true } ) ;
1454
+
1455
+ expect ( result . valid ) . toBeTruthy ( ) ;
1456
+
1457
+ result = val . validate ( data , schema ) ;
1458
+
1459
+ expect ( result . valid ) . toBeFalsy ( ) ;
1460
+ expect ( result . errors . length ) . toBe ( 1 ) ;
1461
+ } ) ;
1462
+
1398
1463
it ( 'should call the transform function when "options.transform" is a function' , function ( ) {
1399
1464
var schema = {
1400
1465
properties : {
0 commit comments