Skip to content

Commit a709b04

Browse files
authored
test(query-devtools/utils): add tests for 'array nested path' and 'primitive' cases of 'deleteNestedDataByPath' (#10673)
1 parent 8dd9724 commit a709b04

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

packages/query-devtools/src/__tests__/utils.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,38 @@ describe('Utils tests', () => {
539539
`)
540540
})
541541

542+
describe('array nested path', () => {
543+
it('should delete nested data inside an array correctly', () => {
544+
const oldData = [
545+
{ id: 1, title: 'first' },
546+
{ id: 2, title: 'second' },
547+
]
548+
549+
const newData = deleteNestedDataByPath(oldData, ['1', 'title'])
550+
551+
expect(newData).not.toBe(oldData)
552+
expect(newData).toMatchInlineSnapshot(`
553+
[
554+
{
555+
"id": 1,
556+
"title": "first",
557+
},
558+
{
559+
"id": 2,
560+
},
561+
]
562+
`)
563+
})
564+
})
565+
566+
describe('primitive', () => {
567+
it('should return primitive data as-is when it is not an Object/Array/Map/Set', () => {
568+
expect(deleteNestedDataByPath(42, ['x'])).toBe(42)
569+
expect(deleteNestedDataByPath('hello', ['x'])).toBe('hello')
570+
expect(deleteNestedDataByPath(null, ['x'])).toBe(null)
571+
})
572+
})
573+
542574
describe('nested data', () => {
543575
it('should delete nested items correctly', () => {
544576
/* eslint-disable cspell/spellchecker */

0 commit comments

Comments
 (0)