-
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.
- Loading branch information
Sean Hamilton
committed
Jul 2, 2019
1 parent
0e744c1
commit 5a00ac1
Showing
1 changed file
with
35 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,35 @@ | ||
import set from '../set'; | ||
|
||
describe('set', () => { | ||
test('should return a new object not a reference', () => { | ||
const obj = {}; | ||
const result = set(obj, 'a', 1); | ||
|
||
expect(result.a).toBe(1); | ||
expect(Object.keys(obj)).toHaveLength(0); | ||
}); | ||
|
||
test('should set the specified value on the object', () => { | ||
const obj = {}; | ||
const result = set(obj, 'a', 1); | ||
|
||
expect(result.a).toBe(1); | ||
}); | ||
|
||
test('should use dot notation for the path', () => { | ||
const obj = {}; | ||
const result = set(obj, 'a.b', 1); | ||
|
||
expect(result.a.b).toBe(1); | ||
}); | ||
|
||
test('should throw TypeError for invalid arguments', () => { | ||
const invalidObj: unknown = 'testing'; | ||
const invalidPath: unknown = 1; | ||
|
||
expect(() => set(invalidObj as OObject, 'test', 'test')) | ||
.toThrow(new TypeError('Expected Object, got string testing')); | ||
expect(() => set({}, invalidPath as string, 'test')) | ||
.toThrow(new TypeError('Expected String, got number 1')); | ||
}); | ||
}); |