@@ -428,16 +428,43 @@ describe('Function: deepMerge', () => {
428428 expect ( result ) . toEqual ( { a : null } ) ;
429429 } ) ;
430430
431- it ( 'handles undefined values in source' , ( ) => {
431+ it ( 'handles undefined values in source (does not overwrite existing value with `undefined`) ' , ( ) => {
432432 // Prepare
433433 const target = { a : 1 , b : 2 } ;
434- const source = { a : undefined } ;
434+ const source = { a : undefined , c : undefined } ;
435435
436436 // Act
437437 const result = deepMerge ( target , source ) ;
438438
439439 // Assess
440- expect ( result ) . toEqual ( { a : undefined , b : 2 } ) ;
440+ expect ( result ) . toStrictEqual ( { a : 1 , b : 2 , c : undefined } ) ;
441+ } ) ;
442+
443+ it ( 'handles undefined values in array of source (does not overwrite existing value with `undefined`)' , ( ) => {
444+ // Prepare
445+ const target = { arr : [ 4 , 5 , 6 ] } ;
446+ const source = { arr : [ 1 , undefined , 3 , undefined ] } ;
447+ source . arr [ 1 ] = undefined ;
448+
449+ // Act
450+ const result = deepMerge ( target , source ) ;
451+
452+ // Assess
453+ expect ( result ) . toStrictEqual ( { arr : [ 1 , 5 , 3 , undefined ] } ) ;
454+ } ) ;
455+
456+ it ( 'handles missing values in array of source (does not overwrite existing value with `undefined`)' , ( ) => {
457+ // Prepare
458+ const target = { arr : [ 4 , 5 , 6 ] } ;
459+ const source = { arr : new Array ( 4 ) } ;
460+ source . arr [ 0 ] = 1 ;
461+ source . arr [ 2 ] = 3 ;
462+
463+ // Act
464+ const result = deepMerge ( target , source ) ;
465+
466+ // Assess
467+ expect ( result ) . toStrictEqual ( { arr : [ 1 , 5 , 3 , undefined ] } ) ;
441468 } ) ;
442469
443470 it ( 'handles Symbol keys (ignores them)' , ( ) => {
0 commit comments