-
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(keyOf): add keyOf function tests
- Loading branch information
Sean Hamilton
committed
Jul 2, 2019
1 parent
5a00ac1
commit cdd196f
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 keyOf from '../keyOf'; | ||
|
||
describe('keyOf', () => { | ||
test('should return the key of the first value matched', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
}; | ||
|
||
expect(keyOf(obj, 1)).toBe('a'); | ||
expect(keyOf(obj, 2)).toBe('b'); | ||
expect(keyOf(obj, 3)).toBe('c'); | ||
}); | ||
|
||
test('should return undefined if the value is not matched', () => { | ||
const obj = { | ||
a: 1, | ||
}; | ||
|
||
expect(keyOf(obj, 2)).toBeUndefined(); | ||
}); | ||
|
||
test('should throw TypeError for invalid arguments', () => { | ||
const invalidObj: unknown = 'testing'; | ||
const invalidFollow: unknown = 'testing'; | ||
|
||
expect(() => keyOf(invalidObj as OObject, 'test')) | ||
.toThrow(new TypeError('Expected Object, got string testing')); | ||
expect(() => keyOf({}, 'test', { | ||
follow: invalidFollow as boolean, | ||
})) | ||
.toThrow(new TypeError('Expected Boolean, got string testing')); | ||
}); | ||
}); |