Skip to content

Commit

Permalink
Add mergeData tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klis87 committed Jul 15, 2024
1 parent 5a744a5 commit f9529cc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/normy/src/merge-data.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { mergeData } from './merge-data';

describe('mergeData', () => {
it('merges data', () => {
expect(mergeData({ x: 1, y: { a: 2, b: 3 } }, { x: 4 })).toEqual({
x: 4,
y: { a: 2, b: 3 },
});
});

it('deeply merges data', () => {
expect(mergeData({ x: 1, y: { a: 2, b: 3 } }, { y: { b: 4 } })).toEqual({
x: 1,
y: { a: 2, b: 4 },
});
});

it('does not mutate params', () => {
const firstParam = { x: 1, y: { a: 2, b: 3 } };
const secondParam = { x: 1, y: { a: 2, b: 4 }, z: 5 };

mergeData(firstParam, secondParam);

expect(firstParam).toEqual({ x: 1, y: { a: 2, b: 3 } });
expect(secondParam).toEqual({ x: 1, y: { a: 2, b: 4 }, z: 5 });
});
});

0 comments on commit f9529cc

Please sign in to comment.