From b4d568fba6fc053c11ea5ae960b14352ebd4949a Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 9 May 2026 14:18:15 +0900 Subject: [PATCH] test(query-devtools/utils): add tests for 'array nested path' and 'primitive' cases of 'deleteNestedDataByPath' --- .../src/__tests__/utils.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/query-devtools/src/__tests__/utils.test.ts b/packages/query-devtools/src/__tests__/utils.test.ts index 0c1fb6ec50..26ae5a93b6 100644 --- a/packages/query-devtools/src/__tests__/utils.test.ts +++ b/packages/query-devtools/src/__tests__/utils.test.ts @@ -539,6 +539,38 @@ describe('Utils tests', () => { `) }) + describe('array nested path', () => { + it('should delete nested data inside an array correctly', () => { + const oldData = [ + { id: 1, title: 'first' }, + { id: 2, title: 'second' }, + ] + + const newData = deleteNestedDataByPath(oldData, ['1', 'title']) + + expect(newData).not.toBe(oldData) + expect(newData).toMatchInlineSnapshot(` + [ + { + "id": 1, + "title": "first", + }, + { + "id": 2, + }, + ] + `) + }) + }) + + describe('primitive', () => { + it('should return primitive data as-is when it is not an Object/Array/Map/Set', () => { + expect(deleteNestedDataByPath(42, ['x'])).toBe(42) + expect(deleteNestedDataByPath('hello', ['x'])).toBe('hello') + expect(deleteNestedDataByPath(null, ['x'])).toBe(null) + }) + }) + describe('nested data', () => { it('should delete nested items correctly', () => { /* eslint-disable cspell/spellchecker */