Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/query-core/src/__tests__/mutationCache.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,31 @@ describe('mutationCache', () => {

expect(testCache.getAll()).toHaveLength(0)
})

test('should still notify removal when removing a mutation that does not exist in the cache', () => {
const testCache = new MutationCache()
const testClient = new QueryClient({ mutationCache: testCache })

const mutation = testCache.build(testClient, {
mutationFn: () => Promise.resolve('data'),
})

expect(testCache.getAll()).toHaveLength(1)
testCache.remove(mutation)
expect(testCache.getAll()).toHaveLength(0)

// Remove again — mutation is already gone from the cache
const callback = vi.fn()
const unsubscribe = testCache.subscribe(callback)
testCache.remove(mutation)

expect(testCache.getAll()).toHaveLength(0)
expect(callback).toHaveBeenCalledTimes(1)
expect(callback).toHaveBeenCalledWith(
expect.objectContaining({ type: 'removed', mutation }),
)

unsubscribe()
})
})
})
Loading