-
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(get): add tests for get function
- Loading branch information
Sean Hamilton
committed
Dec 5, 2018
1 parent
e388847
commit 773a2ca
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 get from '../src/get'; | ||
|
||
describe('get', () => { | ||
test('should return the default value (undefined) if the object specified isn\'t an object', () => { | ||
const got = get('test'); | ||
|
||
expect(got).toBeUndefined(); | ||
}); | ||
|
||
test('should return the default value (undefined) if the object specified is empty', () => { | ||
const got = get({}); | ||
|
||
expect(got).toBeUndefined(); | ||
}); | ||
|
||
test('should return the default value when the object doesn\'t have the path specified', () => { | ||
const a = { | ||
a: 1, | ||
}; | ||
const got = get(a, 'b'); | ||
|
||
expect(got).toBeUndefined(); | ||
}); | ||
|
||
test('should return the specified default value', () => { | ||
const a = { | ||
a: 1, | ||
}; | ||
const got = get(a, 'b', 'default'); | ||
|
||
expect(got).toBe('default'); | ||
}); | ||
|
||
test('should return the specified default value when the path is dot notation', () => { | ||
const a = { | ||
a: { | ||
b: 1, | ||
}, | ||
}; | ||
const got = get(a, 'a.b'); | ||
|
||
expect(got).toBe(1); | ||
}); | ||
}); |