diff --git a/src/object/mergeWith.spec.ts b/src/object/mergeWith.spec.ts index 163aeb26c..c2b0be3d1 100644 --- a/src/object/mergeWith.spec.ts +++ b/src/object/mergeWith.spec.ts @@ -107,4 +107,22 @@ describe('mergeWith', () => { expect(result).toEqual({ a: 3, b: 2 }); }); + + it('should replace non-plain-object target value with plain object from source when merge returns undefined', () => { + const target = { a: 'string', b: 123, c: true }; + const source = { a: { x: 1 }, b: { y: 2 }, c: { z: 3 } }; + + const result = mergeWith(target, source, () => undefined); + + expect(result).toEqual({ a: { x: 1 }, b: { y: 2 }, c: { z: 3 } }); + }); + + it('should handle nested case where non-plain-object is replaced with plain object when merge returns undefined', () => { + const target = { a: { b: null, c: undefined, d: 'text' } }; + const source = { a: { b: { x: 1 }, c: { y: 2 }, d: { z: 3 } } }; + + const result = mergeWith(target, source, () => undefined); + + expect(result).toEqual({ a: { b: { x: 1 }, c: { y: 2 }, d: { z: 3 } } }); + }); });