Skip to content

Commit b63da8a

Browse files
authored
test(query-core/queryCache): add test for 'remove' only deleting the instance currently stored under its 'queryHash' (TanStack#10888)
1 parent bd0a264 commit b63da8a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

packages/query-core/src/__tests__/queryCache.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,22 @@ describe('queryCache', () => {
380380
})
381381
})
382382

383+
describe('QueryCache.remove', () => {
384+
it('should only delete the instance currently stored under its queryHash', () => {
385+
const key = queryKey()
386+
387+
const staleQuery = queryCache.build(queryClient, { queryKey: key })
388+
queryCache.remove(staleQuery)
389+
390+
const currentQuery = queryCache.build(queryClient, { queryKey: key })
391+
expect(currentQuery).not.toBe(staleQuery)
392+
393+
queryCache.remove(staleQuery)
394+
395+
expect(queryCache.get(hashKey(key))).toBe(currentQuery)
396+
})
397+
})
398+
383399
describe('QueryCache.add', () => {
384400
it('should not try to add a query already added to the cache', async () => {
385401
const key = queryKey()

0 commit comments

Comments
 (0)