-
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deleteField inside of an array should now work
* Add basic tests for arrays * Ran prettier * Ran prettier * Add new test for bug * Fix bug regarding preserved values even if field is umounted * Run prettier * Update store subscription when removingFields * Fix delete field * Fix delete field * Fix bug with deleteField inside an array * Fix bug with deleteField inside an array * Fix bug with deleteField inside an array * Improve error * Improve error * Add tests for utils * Add tests for utils * chore: fix test errors, remove errant test utils --------- Co-authored-by: Corbin Crutchley <[email protected]>
- Loading branch information
1 parent
6c9e652
commit 4e8bf2a
Showing
4 changed files
with
181 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { deleteBy, getBy, setBy } from '../utils' | ||
|
||
describe('getBy', () => { | ||
const structure = { | ||
name: 'Marc', | ||
kids: [ | ||
{ name: 'Stephen', age: 10 }, | ||
{ name: 'Taylor', age: 15 }, | ||
], | ||
mother: { | ||
name: 'Lisa', | ||
}, | ||
} | ||
|
||
it('should get subfields by path', () => { | ||
expect(getBy(structure, 'name')).toBe(structure.name) | ||
expect(getBy(structure, 'mother.name')).toBe(structure.mother.name) | ||
}) | ||
|
||
it('should get array subfields by path', () => { | ||
expect(getBy(structure, 'kids.0.name')).toBe(structure.kids[0]!.name) | ||
expect(getBy(structure, 'kids.0.age')).toBe(structure.kids[0]!.age) | ||
}) | ||
}) | ||
|
||
describe('setBy', () => { | ||
const structure = { | ||
name: 'Marc', | ||
kids: [ | ||
{ name: 'Stephen', age: 10 }, | ||
{ name: 'Taylor', age: 15 }, | ||
], | ||
mother: { | ||
name: 'Lisa', | ||
}, | ||
} | ||
|
||
it('should set subfields by path', () => { | ||
expect(setBy(structure, 'name', 'Lisa').name).toBe('Lisa') | ||
expect(setBy(structure, 'mother.name', 'Tina').mother.name).toBe('Tina') | ||
}) | ||
|
||
it('should set array subfields by path', () => { | ||
expect(setBy(structure, 'kids.0.name', 'Taylor').kids[0].name).toBe( | ||
'Taylor', | ||
) | ||
expect(setBy(structure, 'kids.0.age', 20).kids[0].age).toBe(20) | ||
}) | ||
}) | ||
|
||
describe('deleteBy', () => { | ||
const structure = { | ||
name: 'Marc', | ||
kids: [ | ||
{ name: 'Stephen', age: 10 }, | ||
{ name: 'Taylor', age: 15 }, | ||
], | ||
mother: { | ||
name: 'Lisa', | ||
}, | ||
} | ||
|
||
it('should delete subfields by path', () => { | ||
expect(deleteBy(structure, 'name').name).not.toBeDefined() | ||
expect(deleteBy(structure, 'mother.name').mother.name).not.toBeDefined() | ||
}) | ||
|
||
it('should delete array subfields by path', () => { | ||
expect(deleteBy(structure, 'kids.0.name').kids[0].name).not.toBeDefined() | ||
expect(deleteBy(structure, 'kids.0.age').kids[0].age).not.toBeDefined() | ||
}) | ||
}) |
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