Skip to content

Commit 33679a1

Browse files
authored
test(query-core/mutationObserver): add test for skipping 'notify' when 'setOptions' is called with same options (#10098)
1 parent 858aa94 commit 33679a1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,27 @@ describe('mutationObserver', () => {
476476
unsubscribe()
477477
})
478478
})
479+
480+
test('should not notify cache when setOptions is called with same options', () => {
481+
const mutationObserver = new MutationObserver(queryClient, {
482+
mutationFn: (text: string) => Promise.resolve(text),
483+
})
484+
485+
const notifySpy = vi.spyOn(queryClient.getMutationCache(), 'notify')
486+
487+
const unsubscribe = mutationObserver.subscribe(() => undefined)
488+
489+
notifySpy.mockClear()
490+
491+
// Call setOptions with the same options
492+
mutationObserver.setOptions({
493+
mutationFn: mutationObserver.options.mutationFn,
494+
})
495+
496+
expect(notifySpy).not.toHaveBeenCalledWith(
497+
expect.objectContaining({ type: 'observerOptionsUpdated' }),
498+
)
499+
500+
unsubscribe()
501+
})
479502
})

0 commit comments

Comments
 (0)