From e244afe857384bc352c3221901fe51e3bff439ac Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Fri, 5 Jun 2026 23:11:41 +0900 Subject: [PATCH] test(query-core/queryCache): add test for 'remove' only deleting the instance currently stored under its 'queryHash' --- .../query-core/src/__tests__/queryCache.test.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/query-core/src/__tests__/queryCache.test.tsx b/packages/query-core/src/__tests__/queryCache.test.tsx index 1238bcf44a9..c404c1f942b 100644 --- a/packages/query-core/src/__tests__/queryCache.test.tsx +++ b/packages/query-core/src/__tests__/queryCache.test.tsx @@ -380,6 +380,22 @@ describe('queryCache', () => { }) }) + describe('QueryCache.remove', () => { + it('should only delete the instance currently stored under its queryHash', () => { + const key = queryKey() + + const staleQuery = queryCache.build(queryClient, { queryKey: key }) + queryCache.remove(staleQuery) + + const currentQuery = queryCache.build(queryClient, { queryKey: key }) + expect(currentQuery).not.toBe(staleQuery) + + queryCache.remove(staleQuery) + + expect(queryCache.get(hashKey(key))).toBe(currentQuery) + }) + }) + describe('QueryCache.add', () => { it('should not try to add a query already added to the cache', async () => { const key = queryKey()