@@ -165,4 +165,22 @@ describe('toMerged', () => {
165165 expect ( result ) . toEqual ( { a : { b : { c : [ 2 ] , d : 3 } , e : [ 4 ] } } ) ;
166166 expect ( target ) . toEqual ( { a : { b : { c : [ 1 ] } } } ) ;
167167 } ) ;
168+
169+ it ( 'should replace non-plain-object target value with plain object from source' , ( ) => {
170+ const target = { a : 'string' , b : 123 , c : true } ;
171+ const source = { a : { x : 1 } , b : { y : 2 } , c : { z : 3 } } ;
172+ const result = toMerged ( target , source ) ;
173+
174+ expect ( result ) . toEqual ( { a : { x : 1 } , b : { y : 2 } , c : { z : 3 } } ) ;
175+ expect ( target ) . toEqual ( { a : 'string' , b : 123 , c : true } ) ;
176+ } ) ;
177+
178+ it ( 'should handle nested case where non-plain-object is replaced with plain object' , ( ) => {
179+ const target = { a : { b : null , c : undefined , d : 'text' } } ;
180+ const source = { a : { b : { x : 1 } , c : { y : 2 } , d : { z : 3 } } } ;
181+ const result = toMerged ( target , source ) ;
182+
183+ expect ( result ) . toEqual ( { a : { b : { x : 1 } , c : { y : 2 } , d : { z : 3 } } } ) ;
184+ expect ( target ) . toEqual ( { a : { b : null , c : undefined , d : 'text' } } ) ;
185+ } ) ;
168186} ) ;
0 commit comments