From 5a7fd80b326049b10ed7966c80a3a10f41653e86 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 7 Feb 2026 16:21:52 +0900 Subject: [PATCH] test(query-core/mutationCache): add test for 'remove' splicing target mutation from scope with multiple mutations --- .../src/__tests__/mutationCache.test.tsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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]) + }) + }) })