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 fb7fd80a7b7..1e7b81ba971 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/query-core/src/__tests__/mutationCache.test.tsx b/packages/query-core/src/__tests__/mutationCache.test.tsx index 05d4e581dfa..be46802a8e2 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 00caf5704ee..ac4c10ea5b0 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 c404c1f942b..f381bcbccf1 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 a8db8d10c76..2ed4c4c193a 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 79dc3a8e588..9ffcb3ba51b 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() }) diff --git a/packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx b/packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx index 17a53b5bf35..c277169b0ff 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() } diff --git a/packages/vue-query/src/__tests__/useQuery.test.ts b/packages/vue-query/src/__tests__/useQuery.test.ts index d794c97c2b1..698605e872d 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'], }),