Skip to content

Commit

Permalink
test(merge): add merge function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hamilton committed Jul 4, 2019
1 parent c0f0014 commit 47d9a95
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/__tests__/merge.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import merge from '../merge';

describe('merge', () => {
test('should return a new object not a reference', () => {
const obj = {
a: 1,
b: 2,
};

const result = merge(obj, {});
result.a = 2;

expect(obj.a).toBe(1);
});

test('should return an object with the properties of the sources merged on top', () => {
const target = {
a: 1,
b: 2,
};
const sourceA = {
a: 2,
};
const sourceB = {
b: 3,
};

const resultA = merge(target, sourceA);
const resultB = merge(target, sourceA, sourceB);

expect(resultA.a).toBe(2);
expect(resultB.a).toBe(2);
expect(resultB.b).toBe(3);
});

test('', () => {
const invalidObj: unknown = 'testing';

expect(() => merge(invalidObj as OObject, {}))
.toThrow(new TypeError('Expected Object, got string testing'));
expect(() => merge({}, invalidObj as OObject))
.toThrow(new TypeError('Expected Object[], got object testing'));
expect(() => merge({}, {}, invalidObj as OObject))
.toThrow(new TypeError('Expected Object[], got object [object Object],testing'));
});
});

0 comments on commit 47d9a95

Please # to comment.