@@ -385,6 +385,9 @@ describe('empty', function(){
385
385
obj . path = true ;
386
386
387
387
expect ( objectPath . empty ( obj , 'inexistant' ) ) . to . equal ( void 0 ) ;
388
+
389
+ expect ( objectPath . empty ( null , 'path' ) ) . to . equal ( void 0 ) ;
390
+ expect ( objectPath . empty ( void 0 , 'path' ) ) . to . equal ( void 0 ) ;
388
391
} ) ;
389
392
390
393
it ( 'should empty each path according to their types' , function ( ) {
@@ -407,7 +410,9 @@ describe('empty', function(){
407
410
some :'property' ,
408
411
sub : {
409
412
'property' : true
410
- }
413
+ } ,
414
+ nullProp : null ,
415
+ undefinedProp : void 0
411
416
} ,
412
417
instance : new Instance ( )
413
418
} ;
@@ -421,6 +426,17 @@ describe('empty', function(){
421
426
objectPath . empty ( obj , 'object.sub' ) ;
422
427
expect ( obj . object . sub ) . to . deep . equal ( { } ) ;
423
428
429
+ objectPath . empty ( obj , 'object.nullProp' ) ;
430
+ expect ( obj . object . nullProp ) . to . equal ( null ) ;
431
+
432
+ objectPath . empty ( obj , 'object.undefinedProp' ) ;
433
+ expect ( obj . object . undefinedProp ) . to . equal ( void 0 ) ;
434
+ expect ( obj . object ) . to . have . property ( 'undefinedProp' ) ;
435
+
436
+ objectPath . empty ( obj , 'object.notAProp' ) ;
437
+ expect ( obj . object . notAProp ) . to . equal ( void 0 ) ;
438
+ expect ( obj . object ) . to . not . have . property ( 'notAProp' ) ;
439
+
424
440
objectPath . empty ( obj , 'instance.test' ) ;
425
441
//instance.test is not own property, so it shouldn't be emptied
426
442
expect ( obj . instance . test ) . to . be . a ( 'function' ) ;
@@ -452,6 +468,24 @@ describe('del', function(){
452
468
expect ( obj . b . d ) . to . deep . equal ( [ 'a' ] ) ;
453
469
} ) ;
454
470
471
+ it ( 'should remove null and undefined props (but not explode on nested)' , function ( ) {
472
+ var obj = { nullProp : null , undefinedProp : void 0 } ;
473
+ expect ( obj ) . to . have . property ( 'nullProp' ) ;
474
+ expect ( obj ) . to . have . property ( 'undefinedProp' ) ;
475
+
476
+ objectPath . del ( obj , 'nullProp.foo' ) ;
477
+ objectPath . del ( obj , 'undefinedProp.bar' ) ;
478
+ expect ( obj ) . to . have . property ( 'nullProp' ) ;
479
+ expect ( obj ) . to . have . property ( 'undefinedProp' ) ;
480
+ expect ( obj ) . to . deep . equal ( { nullProp : null , undefinedProp : void 0 } ) ;
481
+
482
+ objectPath . del ( obj , 'nullProp' ) ;
483
+ objectPath . del ( obj , 'undefinedProp' ) ;
484
+ expect ( obj ) . to . not . have . property ( 'nullProp' ) ;
485
+ expect ( obj ) . to . not . have . property ( 'undefinedProp' ) ;
486
+ expect ( obj ) . to . deep . equal ( { } ) ;
487
+ } ) ;
488
+
455
489
it ( 'should delete deep paths' , function ( ) {
456
490
var obj = getTestObj ( ) ;
457
491
0 commit comments