From 028d558403ba5c69105493d0ab7d8a320d379acc Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Thu, 5 Feb 2026 21:53:59 +0900 Subject: [PATCH] test(query-core/mutationObserver): add test for skipping 'notify' when 'setOptions' is called with same options --- .../src/__tests__/mutationObserver.test.tsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/query-core/src/__tests__/mutationObserver.test.tsx b/packages/query-core/src/__tests__/mutationObserver.test.tsx index abbcfeac42..cc196f024a 100644 --- a/packages/query-core/src/__tests__/mutationObserver.test.tsx +++ b/packages/query-core/src/__tests__/mutationObserver.test.tsx @@ -476,4 +476,27 @@ describe('mutationObserver', () => { unsubscribe() }) }) + + test('should not notify cache when setOptions is called with same options', () => { + const mutationObserver = new MutationObserver(queryClient, { + mutationFn: (text: string) => Promise.resolve(text), + }) + + const notifySpy = vi.spyOn(queryClient.getMutationCache(), 'notify') + + const unsubscribe = mutationObserver.subscribe(() => undefined) + + notifySpy.mockClear() + + // Call setOptions with the same options + mutationObserver.setOptions({ + mutationFn: mutationObserver.options.mutationFn, + }) + + expect(notifySpy).not.toHaveBeenCalledWith( + expect.objectContaining({ type: 'observerOptionsUpdated' }), + ) + + unsubscribe() + }) })