diff --git a/packages/query-core/src/__tests__/mutationCache.test.tsx b/packages/query-core/src/__tests__/mutationCache.test.tsx index 50337b0e84..7369d20f2d 100644 --- a/packages/query-core/src/__tests__/mutationCache.test.tsx +++ b/packages/query-core/src/__tests__/mutationCache.test.tsx @@ -445,4 +445,27 @@ describe('mutationCache', () => { expect(onSuccess).toHaveBeenCalledTimes(1) }) }) + + describe('remove', () => { + test('should remove only the target mutation from scope when multiple scoped mutations exist', () => { + const testCache = new MutationCache() + const testClient = new QueryClient({ mutationCache: testCache }) + + const mutation1 = testCache.build(testClient, { + scope: { id: 'scope1' }, + mutationFn: () => Promise.resolve('data1'), + }) + const mutation2 = testCache.build(testClient, { + scope: { id: 'scope1' }, + mutationFn: () => Promise.resolve('data2'), + }) + + expect(testCache.getAll()).toHaveLength(2) + + testCache.remove(mutation1) + + expect(testCache.getAll()).toHaveLength(1) + expect(testCache.getAll()).toEqual([mutation2]) + }) + }) })