Skip to content

Commit 858aa94

Browse files
authored
test(query-core/mutationCache): add test for 'remove' splicing target mutation from scope with multiple mutations (#10103)
1 parent e2e5401 commit 858aa94

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/query-core/src/__tests__/mutationCache.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,27 @@ describe('mutationCache', () => {
445445
expect(onSuccess).toHaveBeenCalledTimes(1)
446446
})
447447
})
448+
449+
describe('remove', () => {
450+
test('should remove only the target mutation from scope when multiple scoped mutations exist', () => {
451+
const testCache = new MutationCache()
452+
const testClient = new QueryClient({ mutationCache: testCache })
453+
454+
const mutation1 = testCache.build(testClient, {
455+
scope: { id: 'scope1' },
456+
mutationFn: () => Promise.resolve('data1'),
457+
})
458+
const mutation2 = testCache.build(testClient, {
459+
scope: { id: 'scope1' },
460+
mutationFn: () => Promise.resolve('data2'),
461+
})
462+
463+
expect(testCache.getAll()).toHaveLength(2)
464+
465+
testCache.remove(mutation1)
466+
467+
expect(testCache.getAll()).toHaveLength(1)
468+
expect(testCache.getAll()).toEqual([mutation2])
469+
})
470+
})
448471
})

0 commit comments

Comments
 (0)