Skip to content

Commit 7316404

Browse files
committed
test(utils): add deepMerge spec test
1 parent 6e84ff3 commit 7316404

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

core/src/utils/helpers.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inheritAriaAttributes } from './helpers';
1+
import { deepMerge, inheritAriaAttributes } from './helpers';
22

33
describe('inheritAriaAttributes', () => {
44
it('should inherit aria attributes', () => {
@@ -40,3 +40,26 @@ describe('inheritAriaAttributes', () => {
4040
});
4141
});
4242
});
43+
44+
describe('deepMerge', () => {
45+
it('should merge objects', () => {
46+
const target = { a: 1, b: 2 };
47+
const source = { b: 3, c: 4 };
48+
const result = deepMerge(target, source);
49+
expect(result).toEqual({ a: 1, b: 3, c: 4 });
50+
});
51+
52+
it('should merge objects when target is undefined', () => {
53+
const target = undefined;
54+
const source = { a: 1, b: 2 };
55+
const result = deepMerge(target, source);
56+
expect(result).toEqual({ a: 1, b: 2 });
57+
});
58+
59+
it('should merge objects when source is undefined', () => {
60+
const target = { a: 1, b: 2 };
61+
const source = undefined;
62+
const result = deepMerge(target, source);
63+
expect(result).toEqual({ a: 1, b: 2 });
64+
});
65+
});

core/src/utils/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,9 @@ export const openURL = async (
461461
* Deep merges two objects, with source properties overriding target properties
462462
* @param target The target object to merge into
463463
* @param source The source object to merge from
464-
* @returns The merged object (new object, doesn't modify original)
464+
* @returns The merged object
465465
*/
466466
export const deepMerge = (target: any, source: any): any => {
467-
// Create a new object to avoid modifying the original
468467
const result = { ...target };
469468

470469
for (const key in source) {

0 commit comments

Comments
 (0)