diff --git a/packages/query-core/src/__tests__/mutationCache.test.tsx b/packages/query-core/src/__tests__/mutationCache.test.tsx index 7369d20f2d..d2c16987bc 100644 --- a/packages/query-core/src/__tests__/mutationCache.test.tsx +++ b/packages/query-core/src/__tests__/mutationCache.test.tsx @@ -467,5 +467,21 @@ describe('mutationCache', () => { expect(testCache.getAll()).toHaveLength(1) expect(testCache.getAll()).toEqual([mutation2]) }) + + test('should delete scope when removing the only mutation in that scope', () => { + const testCache = new MutationCache() + const testClient = new QueryClient({ mutationCache: testCache }) + + const mutation = testCache.build(testClient, { + scope: { id: 'scope1' }, + mutationFn: () => Promise.resolve('data'), + }) + + expect(testCache.getAll()).toHaveLength(1) + + testCache.remove(mutation) + + expect(testCache.getAll()).toHaveLength(0) + }) }) })