-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added nested values proposal prototype (#202) * Fixed default response in setNestedObjectValues * Fixed isObject check in setNestedObjectValues * Refactored to remove lodash set and get dependencies * Inlined dlv in utils.js * Fixed mutation bug in setDeep and added setDeep tests * Added array support to setDeep * Fixed tsconfig.json * Fix dlv * Fix generic in touchAllFields * Fix typo
- Loading branch information
1 parent
e40dd9e
commit 3a8e620
Showing
4 changed files
with
152 additions
and
45 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,61 @@ | ||
import { setDeep } from '../src/utils'; | ||
|
||
describe('helpers', () => { | ||
describe('setDeep', () => { | ||
it('sets flat value', () => { | ||
const obj = { x: 'y' }; | ||
const newObj = setDeep('flat', 'value', obj); | ||
expect(obj).toEqual({ x: 'y' }); | ||
expect(newObj).toEqual({ x: 'y', flat: 'value' }); | ||
}); | ||
|
||
it('sets nested value', () => { | ||
const obj = { x: 'y' }; | ||
const newObj = setDeep('nested.value', 'nested value', obj); | ||
expect(obj).toEqual({ x: 'y' }); | ||
expect(newObj).toEqual({ x: 'y', nested: { value: 'nested value' } }); | ||
}); | ||
|
||
it('updates nested value', () => { | ||
const obj = { x: 'y', nested: { value: 'a' } }; | ||
const newObj = setDeep('nested.value', 'b', obj); | ||
expect(obj).toEqual({ x: 'y', nested: { value: 'a' } }); | ||
expect(newObj).toEqual({ x: 'y', nested: { value: 'b' } }); | ||
}); | ||
|
||
it('sets new array', () => { | ||
const obj = { x: 'y' }; | ||
const newObj = setDeep('nested.0', 'value', obj); | ||
expect(obj).toEqual({ x: 'y' }); | ||
expect(newObj).toEqual({ x: 'y', nested: ['value'] }); | ||
}); | ||
|
||
it('updates nested array value', () => { | ||
const obj = { x: 'y', nested: ['a'] }; | ||
const newObj = setDeep('nested.0', 'b', obj); | ||
expect(obj).toEqual({ x: 'y', nested: ['a'] }); | ||
expect(newObj).toEqual({ x: 'y', nested: ['b'] }); | ||
}); | ||
|
||
it('adds new item to nested array', () => { | ||
const obj = { x: 'y', nested: ['a'] }; | ||
const newObj = setDeep('nested.1', 'b', obj); | ||
expect(obj).toEqual({ x: 'y', nested: ['a'] }); | ||
expect(newObj).toEqual({ x: 'y', nested: ['a', 'b'] }); | ||
}); | ||
|
||
it('sticks to object with int key when defined', () => { | ||
const obj = { x: 'y', nested: { 0: 'a' } }; | ||
const newObj = setDeep('nested.0', 'b', obj); | ||
expect(obj).toEqual({ x: 'y', nested: { 0: 'a' } }); | ||
expect(newObj).toEqual({ x: 'y', nested: { 0: 'b' } }); | ||
}); | ||
|
||
it('supports bracket path', () => { | ||
const obj = { x: 'y' }; | ||
const newObj = setDeep('nested[0]', 'value', obj); | ||
expect(obj).toEqual({ x: 'y' }); | ||
expect(newObj).toEqual({ x: 'y', nested: ['value'] }); | ||
}); | ||
}); | ||
}); |