Skip to content

Commit 17d35bc

Browse files
authored
test(object/mergeWith): add test cases for replacing non-plain-object with plain object (#1500)
1 parent ff285ec commit 17d35bc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/object/mergeWith.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,22 @@ describe('mergeWith', () => {
107107

108108
expect(result).toEqual({ a: 3, b: 2 });
109109
});
110+
111+
it('should replace non-plain-object target value with plain object from source when merge returns undefined', () => {
112+
const target = { a: 'string', b: 123, c: true };
113+
const source = { a: { x: 1 }, b: { y: 2 }, c: { z: 3 } };
114+
115+
const result = mergeWith(target, source, () => undefined);
116+
117+
expect(result).toEqual({ a: { x: 1 }, b: { y: 2 }, c: { z: 3 } });
118+
});
119+
120+
it('should handle nested case where non-plain-object is replaced with plain object when merge returns undefined', () => {
121+
const target = { a: { b: null, c: undefined, d: 'text' } };
122+
const source = { a: { b: { x: 1 }, c: { y: 2 }, d: { z: 3 } } };
123+
124+
const result = mergeWith(target, source, () => undefined);
125+
126+
expect(result).toEqual({ a: { b: { x: 1 }, c: { y: 2 }, d: { z: 3 } } });
127+
});
110128
});

0 commit comments

Comments
 (0)