-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(merge): add merge function tests
- Loading branch information
Sean Hamilton
committed
Jul 4, 2019
1 parent
c0f0014
commit 47d9a95
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
}); |