From aa1f9d7bf1c1d7d229ddb45ddbd897d373f5b2e5 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sun, 12 Jul 2026 12:09:38 +0900 Subject: [PATCH 1/3] test({vue,angular}-query): pin the reactive refetch call with 'toHaveBeenNthCalledWith' (#11051) --- .../src/__tests__/inject-query.test.ts | 8 +++++--- packages/vue-query/src/__tests__/useQuery.test.ts | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/angular-query-experimental/src/__tests__/inject-query.test.ts b/packages/angular-query-experimental/src/__tests__/inject-query.test.ts index fb7fd80a7b..1e7b81ba97 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-query.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-query.test.ts @@ -436,7 +436,7 @@ describe('injectQuery', () => { expect(spy).toHaveBeenCalledTimes(2) // should call queryFn with context containing the new queryKey - expect(spy).toHaveBeenCalledWith({ + expect(spy).toHaveBeenNthCalledWith(2, { client: queryClient, meta: undefined, queryKey: key2, @@ -528,7 +528,8 @@ describe('injectQuery', () => { void query.refetch().then(() => { expect(fetchFn).toHaveBeenCalledTimes(1) - expect(fetchFn).toHaveBeenCalledWith( + expect(fetchFn).toHaveBeenNthCalledWith( + 1, expect.objectContaining({ queryKey: [...key, 'key11'], }), @@ -541,7 +542,8 @@ describe('injectQuery', () => { void query.refetch().then(() => { expect(fetchFn).toHaveBeenCalledTimes(2) - expect(fetchFn).toHaveBeenCalledWith( + expect(fetchFn).toHaveBeenNthCalledWith( + 2, expect.objectContaining({ queryKey: [...key, 'key12'], }), diff --git a/packages/vue-query/src/__tests__/useQuery.test.ts b/packages/vue-query/src/__tests__/useQuery.test.ts index d794c97c2b..698605e872 100644 --- a/packages/vue-query/src/__tests__/useQuery.test.ts +++ b/packages/vue-query/src/__tests__/useQuery.test.ts @@ -332,7 +332,8 @@ describe('useQuery', () => { expect(fetchFn).not.toHaveBeenCalled() await query.refetch() expect(fetchFn).toHaveBeenCalledTimes(1) - expect(fetchFn).toHaveBeenCalledWith( + expect(fetchFn).toHaveBeenNthCalledWith( + 1, expect.objectContaining({ queryKey: [...key, 'key11'], }), @@ -341,7 +342,8 @@ describe('useQuery', () => { keyRef.value = 'key12' await query.refetch() expect(fetchFn).toHaveBeenCalledTimes(2) - expect(fetchFn).toHaveBeenCalledWith( + expect(fetchFn).toHaveBeenNthCalledWith( + 2, expect.objectContaining({ queryKey: [...key, 'key12'], }), From 8773a1501fe0c964f62460a69f4d6646d4f0ed62 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sun, 12 Jul 2026 12:28:02 +0900 Subject: [PATCH 2/3] test(query-devtools/PiPContext): assert exact spy arguments instead of 'objectContaining'/'stringContaining' (#11052) --- .../src/__tests__/contexts/PiPContext.test.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx b/packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx index 17a53b5bf3..c277169b0f 100644 --- a/packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx +++ b/packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx @@ -367,7 +367,7 @@ describe('PiPContext', () => { }) expect(consoleError).toHaveBeenCalledWith( - expect.stringContaining('Failed to open popup'), + 'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.', ) expect(localStorage.getItem('TanstackQueryDevtools.pip_open')).toBe( 'false', @@ -428,10 +428,11 @@ describe('PiPContext', () => { disabled: true, }) - expect(observeSpy).toHaveBeenCalledWith( - gooberStyle, - expect.objectContaining({ childList: true, subtree: true }), - ) + expect(observeSpy).toHaveBeenCalledWith(gooberStyle, { + childList: true, + subtree: true, + characterDataOldValue: true, + }) } finally { gooberStyle.remove() } From b2ce5bcecb367363e58cc814cc035ea572f09acb Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sun, 12 Jul 2026 13:26:02 +0900 Subject: [PATCH 3/3] test(query-core): assert exact cache event payloads in subscribe callbacks (#11053) test(query-core): assert exact cache event arguments in subscribe callbacks --- .../query-core/src/__tests__/mutationCache.test.tsx | 4 +--- packages/query-core/src/__tests__/query.test.tsx | 7 ++----- packages/query-core/src/__tests__/queryCache.test.tsx | 10 ++++++---- packages/query-core/src/__tests__/queryClient.test.tsx | 10 +++++++++- .../query-core/src/__tests__/queryObserver.test.tsx | 9 ++++++--- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/packages/query-core/src/__tests__/mutationCache.test.tsx b/packages/query-core/src/__tests__/mutationCache.test.tsx index 05d4e581df..be46802a8e 100644 --- a/packages/query-core/src/__tests__/mutationCache.test.tsx +++ b/packages/query-core/src/__tests__/mutationCache.test.tsx @@ -503,9 +503,7 @@ describe('mutationCache', () => { expect(testCache.getAll()).toHaveLength(0) expect(callback).toHaveBeenCalledTimes(1) - expect(callback).toHaveBeenCalledWith( - expect.objectContaining({ type: 'removed', mutation }), - ) + expect(callback).toHaveBeenCalledWith({ type: 'removed', mutation }) unsubscribe() }) diff --git a/packages/query-core/src/__tests__/query.test.tsx b/packages/query-core/src/__tests__/query.test.tsx index 00caf5704e..ac4c10ea5b 100644 --- a/packages/query-core/src/__tests__/query.test.tsx +++ b/packages/query-core/src/__tests__/query.test.tsx @@ -966,13 +966,10 @@ describe('query', () => { const unsubscribe = queryClient.getQueryCache().subscribe(fn) queryClient.setQueryData(key, 'data') + const query = queryClient.getQueryCache().find({ queryKey: key }) await vi.advanceTimersByTimeAsync(10) - expect(fn).toHaveBeenCalledWith( - expect.objectContaining({ - type: 'removed', - }), - ) + expect(fn).toHaveBeenLastCalledWith({ type: 'removed', query }) expect(queryClient.getQueryCache().findAll()).toHaveLength(0) diff --git a/packages/query-core/src/__tests__/queryCache.test.tsx b/packages/query-core/src/__tests__/queryCache.test.tsx index c404c1f942..f381bcbccf 100644 --- a/packages/query-core/src/__tests__/queryCache.test.tsx +++ b/packages/query-core/src/__tests__/queryCache.test.tsx @@ -24,7 +24,7 @@ describe('queryCache', () => { const unsubscribe = queryCache.subscribe(subscriber) queryClient.setQueryData(key, 'foo') const query = queryCache.find({ queryKey: key }) - expect(subscriber).toHaveBeenCalledWith({ query, type: 'added' }) + expect(subscriber).toHaveBeenNthCalledWith(1, { query, type: 'added' }) unsubscribe() }) @@ -37,7 +37,8 @@ describe('queryCache', () => { queryFn: () => sleep(100).then(() => 'data'), }) await vi.advanceTimersByTimeAsync(100) - expect(callback).toHaveBeenCalled() + const query = queryCache.find({ queryKey: key }) + expect(callback).toHaveBeenNthCalledWith(1, { query, type: 'added' }) }) it('should notify query cache when a query becomes stale', async () => { @@ -89,7 +90,7 @@ describe('queryCache', () => { }) await vi.advanceTimersByTimeAsync(100) const query = queryCache.find({ queryKey: key }) - expect(callback).toHaveBeenCalledWith({ query, type: 'added' }) + expect(callback).toHaveBeenNthCalledWith(1, { query, type: 'added' }) }) it('should notify subscribers when new query with initialData is added', async () => { @@ -102,7 +103,8 @@ describe('queryCache', () => { initialData: 'initial', }) await vi.advanceTimersByTimeAsync(100) - expect(callback).toHaveBeenCalled() + const query = queryCache.find({ queryKey: key }) + expect(callback).toHaveBeenNthCalledWith(1, { query, type: 'added' }) }) it('should be able to limit cache size', async () => { diff --git a/packages/query-core/src/__tests__/queryClient.test.tsx b/packages/query-core/src/__tests__/queryClient.test.tsx index a8db8d10c7..2ed4c4c193 100644 --- a/packages/query-core/src/__tests__/queryClient.test.tsx +++ b/packages/query-core/src/__tests__/queryClient.test.tsx @@ -1614,7 +1614,15 @@ describe('queryClient', () => { queryClient.resetQueries({ queryKey: key }) - expect(callback).toHaveBeenCalled() + const query = queryCache.find({ queryKey: key }) + expect(callback).toHaveBeenNthCalledWith( + 1, + expect.objectContaining({ + type: 'updated', + query, + action: expect.objectContaining({ type: 'setState' }), + }), + ) }) it('should reset query', async () => { diff --git a/packages/query-core/src/__tests__/queryObserver.test.tsx b/packages/query-core/src/__tests__/queryObserver.test.tsx index 79dc3a8e58..9ffcb3ba51 100644 --- a/packages/query-core/src/__tests__/queryObserver.test.tsx +++ b/packages/query-core/src/__tests__/queryObserver.test.tsx @@ -1240,10 +1240,13 @@ describe('queryObserver', () => { const unsubscribe = queryClient.getQueryCache().subscribe(spy) observer.setOptions({ queryKey: key, enabled: false, refetchInterval: 10 }) + const query = queryClient.getQueryCache().find({ queryKey: key }) expect(spy).toHaveBeenCalledTimes(1) - expect(spy).toHaveBeenCalledWith( - expect.objectContaining({ type: 'observerOptionsUpdated' }), - ) + expect(spy).toHaveBeenCalledWith({ + type: 'observerOptionsUpdated', + query, + observer, + }) unsubscribe() })