diff --git a/packages/query-core/src/__tests__/queryCache.test.tsx b/packages/query-core/src/__tests__/queryCache.test.tsx index 1238bcf44a..c404c1f942 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()