From c2763642c793b046a28b01fe5f490abafd62f611 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Tue, 24 Feb 2026 17:03:39 +0900 Subject: [PATCH] test(query-core/mutationCache): add test for deleting scope when removing the only mutation in that scope --- .../src/__tests__/mutationCache.test.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/query-core/src/__tests__/mutationCache.test.tsx b/packages/query-core/src/__tests__/mutationCache.test.tsx index 7369d20f2da..d2c16987bcc 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) + }) }) })