-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for nested object search (#45)
* test: add tests for nested object search * fix: import error
- Loading branch information
1 parent
fbfd1f5
commit 68bc0c5
Showing
10 changed files
with
90 additions
and
15 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
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
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
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,28 @@ | ||
import { getObjValue } from '../../src/lib/utils'; | ||
import type { DataObjectWithNull } from '../../src/lib/types'; | ||
|
||
const data: DataObjectWithNull = { | ||
name: 'John', | ||
address: null, | ||
father: { | ||
name: 'Jack', | ||
age: 50, | ||
}, | ||
}; | ||
|
||
test('key is not exist', () => { | ||
expect(getObjValue(data, 'notExist')).toBeUndefined(); | ||
expect(getObjValue(data, ['father', 'notExist'])).toBeUndefined(); | ||
}); | ||
|
||
test('key is string', () => { | ||
expect(getObjValue(data, 'name')).toBe('John'); | ||
expect(getObjValue(data, 'address')).toBeNull(); | ||
expect(getObjValue(data, 'father.name')).toBe('Jack'); | ||
}); | ||
|
||
test('key is string[]', () => { | ||
expect(getObjValue(data, ['name'])).toBe('John'); | ||
expect(getObjValue(data, ['address'])).toBeNull(); | ||
expect(getObjValue(data, ['father', 'name'])).toBe('Jack'); | ||
}); |
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
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
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
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
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
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