Skip to content

Commit 35e7d20

Browse files
authored
test(object/toMerged): add test cases for replacing non-plain-object with plain object (toss#1499)
1 parent 17d35bc commit 35e7d20

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/object/toMerged.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)