Skip to content

Commit 79dee50

Browse files
test(query-core/mutationCache): add test for removing a mutation that does not exist in the cache (#10423)
* test(query-core/mutationCache): add test for removing a mutation that does not exist in the cache * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent f699190 commit 79dee50

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,31 @@ describe('mutationCache', () => {
483483

484484
expect(testCache.getAll()).toHaveLength(0)
485485
})
486+
487+
test('should still notify removal when removing a mutation that does not exist in the cache', () => {
488+
const testCache = new MutationCache()
489+
const testClient = new QueryClient({ mutationCache: testCache })
490+
491+
const mutation = testCache.build(testClient, {
492+
mutationFn: () => Promise.resolve('data'),
493+
})
494+
495+
expect(testCache.getAll()).toHaveLength(1)
496+
testCache.remove(mutation)
497+
expect(testCache.getAll()).toHaveLength(0)
498+
499+
// Remove again — mutation is already gone from the cache
500+
const callback = vi.fn()
501+
const unsubscribe = testCache.subscribe(callback)
502+
testCache.remove(mutation)
503+
504+
expect(testCache.getAll()).toHaveLength(0)
505+
expect(callback).toHaveBeenCalledTimes(1)
506+
expect(callback).toHaveBeenCalledWith(
507+
expect.objectContaining({ type: 'removed', mutation }),
508+
)
509+
510+
unsubscribe()
511+
})
486512
})
487513
})

0 commit comments

Comments
 (0)