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() + }) })