-
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
cdd196f
commit dfdf23d
Showing
1 changed file
with
44 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,44 @@ | ||
import keys from '../keys'; | ||
|
||
describe('keys', () => { | ||
test('should return an array of the objects keys', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
}; | ||
|
||
expect(keys(obj)).toHaveLength(3); | ||
expect(keys(obj)[0]).toBe('a'); | ||
expect(keys(obj)[1]).toBe('b'); | ||
expect(keys(obj)[2]).toBe('c'); | ||
}); | ||
|
||
test('should return deep object keys in dot notation if follow is true', () => { | ||
const obj = { | ||
a: 1, | ||
b: { | ||
c: 2, | ||
}, | ||
}; | ||
|
||
expect(keys(obj, { | ||
follow: false, | ||
})[1]).toBe('b'); | ||
expect(keys(obj, { | ||
follow: true, | ||
})[1]).toBe('b.c'); | ||
}); | ||
|
||
test('', () => { | ||
const invalidObj: unknown = 'testing'; | ||
const invalidFollow: unknown = 'testing'; | ||
|
||
expect(() => keys(invalidObj as OObject)) | ||
.toThrow(new TypeError('Expected Object, got string testing')); | ||
expect(() => keys({}, { | ||
follow: invalidFollow as boolean, | ||
})) | ||
.toThrow(new TypeError('Expected Boolean, got string testing')); | ||
}); | ||
}); |