From 1cb2619058077327042b97d6abaececd731ac26c Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 25 Oct 2025 00:31:37 +0900 Subject: [PATCH] test(object/mergeWith): add test cases for replacing non-plain-object with plain object --- src/object/mergeWith.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 } } }); + }); });