Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/object/mergeWith.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } });
});
});