@tanstack/react-query 5.0.0-alpha.3 → 5.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "5.0.0-alpha.3",
3
+ "version": "5.0.0-alpha.5",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "react-error-boundary": "^3.1.4"
36
36
  },
37
37
  "dependencies": {
38
- "@tanstack/query-core": "5.0.0-alpha.3"
38
+ "@tanstack/query-core": "5.0.0-alpha.5"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": "^18.0.0",
@@ -54,7 +54,7 @@
54
54
  "clean": "rimraf ./build",
55
55
  "test:eslint": "eslint --ext .ts,.tsx ./src",
56
56
  "test:types": "tsc",
57
- "test:lib": "jest --config ./jest.config.ts",
57
+ "test:lib": "vitest run --coverage",
58
58
  "test:lib:dev": "pnpm run test:lib --watch",
59
59
  "build:types": "tsc --build"
60
60
  }
@@ -8,9 +8,10 @@ import {
8
8
  useQuery,
9
9
  dehydrate,
10
10
  HydrationBoundary,
11
- } from '@tanstack/react-query'
11
+ } from '..'
12
12
  import { createQueryClient, sleep } from './utils'
13
13
  import * as coreModule from '@tanstack/query-core'
14
+ import { vi } from 'vitest'
14
15
 
15
16
  describe('React hydration', () => {
16
17
  const fetchData: (value: string) => Promise<string> = (value) =>
@@ -213,7 +214,7 @@ describe('React hydration', () => {
213
214
  const queryCache = new QueryCache()
214
215
  const queryClient = createQueryClient({ queryCache })
215
216
 
216
- const hydrateSpy = jest.spyOn(coreModule, 'hydrate')
217
+ const hydrateSpy = vi.spyOn(coreModule, 'hydrate')
217
218
 
218
219
  function Page() {
219
220
  return null
@@ -237,7 +238,7 @@ describe('React hydration', () => {
237
238
  const queryCache = new QueryCache()
238
239
  const queryClient = createQueryClient({ queryCache })
239
240
 
240
- const hydrateSpy = jest.spyOn(coreModule, 'hydrate')
241
+ const hydrateSpy = vi.spyOn(coreModule, 'hydrate')
241
242
 
242
243
  function Page() {
243
244
  return null
@@ -3,6 +3,7 @@ import { render, waitFor } from '@testing-library/react'
3
3
 
4
4
  import { sleep, queryKey, createQueryClient } from './utils'
5
5
  import { QueryClientProvider, QueryCache, useQuery, useQueryClient } from '..'
6
+ import { vi } from 'vitest'
6
7
 
7
8
  describe('QueryClientProvider', () => {
8
9
  test('sets a specific cache for all queries to use', async () => {
@@ -142,7 +143,7 @@ describe('QueryClientProvider', () => {
142
143
 
143
144
  describe('useQueryClient', () => {
144
145
  test('should throw an error if no query client has been set', () => {
145
- const consoleMock = jest
146
+ const consoleMock = vi
146
147
  .spyOn(console, 'error')
147
148
  .mockImplementation(() => undefined)
148
149
 
@@ -4,6 +4,7 @@ import * as React from 'react'
4
4
 
5
5
  import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
6
6
  import { QueryCache, QueryErrorResetBoundary, useQuery } from '..'
7
+ import { vi } from 'vitest'
7
8
 
8
9
  // TODO: This should be removed with the types for react-error-boundary get updated.
9
10
  declare module 'react-error-boundary' {
@@ -17,7 +18,7 @@ describe('QueryErrorResetBoundary', () => {
17
18
  const queryClient = createQueryClient({ queryCache })
18
19
 
19
20
  it('should retry fetch if the reset error boundary has been reset', async () => {
20
- const consoleMock = jest
21
+ const consoleMock = vi
21
22
  .spyOn(console, 'error')
22
23
  .mockImplementation(() => undefined)
23
24
  const key = queryKey()
@@ -75,7 +76,7 @@ describe('QueryErrorResetBoundary', () => {
75
76
  })
76
77
 
77
78
  it('should not throw error if query is disabled', async () => {
78
- const consoleMock = jest
79
+ const consoleMock = vi
79
80
  .spyOn(console, 'error')
80
81
  .mockImplementation(() => undefined)
81
82
  const key = queryKey()
@@ -139,7 +140,7 @@ describe('QueryErrorResetBoundary', () => {
139
140
  })
140
141
 
141
142
  it('should not throw error if query is disabled, and refetch if query becomes enabled again', async () => {
142
- const consoleMock = jest
143
+ const consoleMock = vi
143
144
  .spyOn(console, 'error')
144
145
  .mockImplementation(() => undefined)
145
146
 
@@ -205,7 +206,7 @@ describe('QueryErrorResetBoundary', () => {
205
206
  })
206
207
 
207
208
  it('should throw error if query is disabled and manually refetched', async () => {
208
- const consoleMock = jest
209
+ const consoleMock = vi
209
210
  .spyOn(console, 'error')
210
211
  .mockImplementation(() => undefined)
211
212
 
@@ -267,7 +268,7 @@ describe('QueryErrorResetBoundary', () => {
267
268
  })
268
269
 
269
270
  it('should not retry fetch if the reset error boundary has not been reset', async () => {
270
- const consoleMock = jest
271
+ const consoleMock = vi
271
272
  .spyOn(console, 'error')
272
273
  .mockImplementation(() => undefined)
273
274
 
@@ -325,7 +326,7 @@ describe('QueryErrorResetBoundary', () => {
325
326
  })
326
327
 
327
328
  it('should retry fetch if the reset error boundary has been reset and the query contains data from a previous fetch', async () => {
328
- const consoleMock = jest
329
+ const consoleMock = vi
329
330
  .spyOn(console, 'error')
330
331
  .mockImplementation(() => undefined)
331
332
 
@@ -385,7 +386,7 @@ describe('QueryErrorResetBoundary', () => {
385
386
  })
386
387
 
387
388
  it('should not retry fetch if the reset error boundary has not been reset after a previous reset', async () => {
388
- const consoleMock = jest
389
+ const consoleMock = vi
389
390
  .spyOn(console, 'error')
390
391
  .mockImplementation(() => undefined)
391
392
 
@@ -453,7 +454,7 @@ describe('QueryErrorResetBoundary', () => {
453
454
  })
454
455
 
455
456
  it('should throw again on error after the reset error boundary has been reset', async () => {
456
- const consoleMock = jest
457
+ const consoleMock = vi
457
458
  .spyOn(console, 'error')
458
459
  .mockImplementation(() => undefined)
459
460
 
@@ -511,7 +512,7 @@ describe('QueryErrorResetBoundary', () => {
511
512
  })
512
513
 
513
514
  it('should never render the component while the query is in error state', async () => {
514
- const consoleMock = jest
515
+ const consoleMock = vi
515
516
  .spyOn(console, 'error')
516
517
  .mockImplementation(() => undefined)
517
518
 
@@ -578,7 +579,7 @@ describe('QueryErrorResetBoundary', () => {
578
579
  })
579
580
 
580
581
  it('should render children', async () => {
581
- const consoleMock = jest
582
+ const consoleMock = vi
582
583
  .spyOn(console, 'error')
583
584
  .mockImplementation(() => undefined)
584
585
 
@@ -602,7 +603,7 @@ describe('QueryErrorResetBoundary', () => {
602
603
  })
603
604
 
604
605
  it('should show error boundary when using tracked queries even though we do not track the error field', async () => {
605
- const consoleMock = jest
606
+ const consoleMock = vi
606
607
  .spyOn(console, 'error')
607
608
  .mockImplementation(() => undefined)
608
609
 
@@ -4,6 +4,7 @@ import ReactDOMTestUtils from 'react-dom/test-utils'
4
4
  import ReactDOMServer from 'react-dom/server'
5
5
  // eslint-disable-next-line import/no-unresolved -- types only for module augmentation
6
6
  import type {} from 'react-dom/next'
7
+ import { vi } from 'vitest'
7
8
 
8
9
  import {
9
10
  useQuery,
@@ -46,12 +47,12 @@ describe('Server side rendering with de/rehydration', () => {
46
47
  globalThis.IS_REACT_ACT_ENVIRONMENT = previousIsReactActEnvironment
47
48
  })
48
49
  it('should not mismatch on success', async () => {
49
- const consoleMock = jest.spyOn(console, 'error')
50
+ const consoleMock = vi.spyOn(console, 'error')
50
51
  consoleMock.mockImplementation(() => undefined)
51
52
 
52
- const fetchDataSuccess = jest.fn<
53
- ReturnType<typeof fetchData>,
54
- Parameters<typeof fetchData>
53
+ const fetchDataSuccess = vi.fn<
54
+ Parameters<typeof fetchData>,
55
+ ReturnType<typeof fetchData>
55
56
  >(fetchData)
56
57
 
57
58
  // -- Shared part --
@@ -127,10 +128,10 @@ describe('Server side rendering with de/rehydration', () => {
127
128
  })
128
129
 
129
130
  it('should not mismatch on error', async () => {
130
- const consoleMock = jest.spyOn(console, 'error')
131
+ const consoleMock = vi.spyOn(console, 'error')
131
132
  consoleMock.mockImplementation(() => undefined)
132
133
 
133
- const fetchDataError = jest.fn(() => {
134
+ const fetchDataError = vi.fn(() => {
134
135
  throw new Error('fetchDataError')
135
136
  })
136
137
 
@@ -207,12 +208,12 @@ describe('Server side rendering with de/rehydration', () => {
207
208
  })
208
209
 
209
210
  it('should not mismatch on queries that were not prefetched', async () => {
210
- const consoleMock = jest.spyOn(console, 'error')
211
+ const consoleMock = vi.spyOn(console, 'error')
211
212
  consoleMock.mockImplementation(() => undefined)
212
213
 
213
- const fetchDataSuccess = jest.fn<
214
- ReturnType<typeof fetchData>,
215
- Parameters<typeof fetchData>
214
+ const fetchDataSuccess = vi.fn<
215
+ Parameters<typeof fetchData>,
216
+ ReturnType<typeof fetchData>
216
217
  >(fetchData)
217
218
 
218
219
  // -- Shared part --
@@ -1,20 +1,17 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
1
  import * as React from 'react'
6
2
  // @ts-ignore
7
3
  import { renderToString } from 'react-dom/server'
8
4
 
9
5
  import { sleep, queryKey, createQueryClient } from './utils'
10
6
  import { useQuery, QueryClientProvider, QueryCache, useInfiniteQuery } from '..'
7
+ import { vi } from 'vitest'
11
8
 
12
9
  describe('Server Side Rendering', () => {
13
10
  it('should not trigger fetch', () => {
14
11
  const queryCache = new QueryCache()
15
12
  const queryClient = createQueryClient({ queryCache })
16
13
  const key = queryKey()
17
- const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
14
+ const queryFn = vi.fn().mockReturnValue('data')
18
15
 
19
16
  function Page() {
20
17
  const query = useQuery({ queryKey: key, queryFn })
@@ -57,7 +54,7 @@ describe('Server Side Rendering', () => {
57
54
  const queryCache = new QueryCache()
58
55
  const queryClient = createQueryClient({ queryCache })
59
56
  const key = queryKey()
60
- const queryFn = jest.fn(() => {
57
+ const queryFn = vi.fn(() => {
61
58
  sleep(10)
62
59
  return 'data'
63
60
  })
@@ -125,7 +122,7 @@ describe('Server Side Rendering', () => {
125
122
  const queryCache = new QueryCache()
126
123
  const queryClient = createQueryClient({ queryCache })
127
124
  const key = queryKey()
128
- const queryFn = jest.fn(async () => {
125
+ const queryFn = vi.fn(async () => {
129
126
  await sleep(5)
130
127
  return 'page 1'
131
128
  })
@@ -11,6 +11,7 @@ import {
11
11
  useQueryErrorResetBoundary,
12
12
  } from '..'
13
13
  import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
14
+ import { vi } from 'vitest'
14
15
 
15
16
  describe("useQuery's in Suspense mode", () => {
16
17
  const queryCache = new QueryCache()
@@ -119,7 +120,7 @@ describe("useQuery's in Suspense mode", () => {
119
120
  it('should not call the queryFn twice when used in Suspense mode', async () => {
120
121
  const key = queryKey()
121
122
 
122
- const queryFn = jest.fn<string, unknown[]>()
123
+ const queryFn = vi.fn<unknown[], string>()
123
124
  queryFn.mockImplementation(() => {
124
125
  sleep(10)
125
126
  return 'data'
@@ -192,7 +193,7 @@ describe("useQuery's in Suspense mode", () => {
192
193
  it('should call onSuccess on the first successful call', async () => {
193
194
  const key = queryKey()
194
195
 
195
- const successFn = jest.fn()
196
+ const successFn = vi.fn()
196
197
 
197
198
  function Page() {
198
199
  useQuery({
@@ -225,8 +226,8 @@ describe("useQuery's in Suspense mode", () => {
225
226
  it('should call every onSuccess handler within a suspense boundary', async () => {
226
227
  const key = queryKey()
227
228
 
228
- const successFn1 = jest.fn()
229
- const successFn2 = jest.fn()
229
+ const successFn1 = vi.fn()
230
+ const successFn2 = vi.fn()
230
231
 
231
232
  function FirstComponent() {
232
233
  useQuery({
@@ -273,7 +274,7 @@ describe("useQuery's in Suspense mode", () => {
273
274
 
274
275
  // https://github.com/tannerlinsley/react-query/issues/468
275
276
  it('should reset error state if new component instances are mounted', async () => {
276
- const consoleMock = jest
277
+ const consoleMock = vi
277
278
  .spyOn(console, 'error')
278
279
  .mockImplementation(() => undefined)
279
280
  const key = queryKey()
@@ -345,7 +346,7 @@ describe("useQuery's in Suspense mode", () => {
345
346
  })
346
347
 
347
348
  it('should retry fetch if the reset error boundary has been reset', async () => {
348
- const consoleMock = jest
349
+ const consoleMock = vi
349
350
  .spyOn(console, 'error')
350
351
  .mockImplementation(() => undefined)
351
352
  const key = queryKey()
@@ -510,7 +511,7 @@ describe("useQuery's in Suspense mode", () => {
510
511
  })
511
512
 
512
513
  it('should retry fetch if the reset error boundary has been reset with global hook', async () => {
513
- const consoleMock = jest
514
+ const consoleMock = vi
514
515
  .spyOn(console, 'error')
515
516
  .mockImplementation(() => undefined)
516
517
  const key = queryKey()
@@ -574,7 +575,7 @@ describe("useQuery's in Suspense mode", () => {
574
575
  })
575
576
 
576
577
  it('should throw errors to the error boundary by default', async () => {
577
- const consoleMock = jest
578
+ const consoleMock = vi
578
579
  .spyOn(console, 'error')
579
580
  .mockImplementation(() => undefined)
580
581
  const key = queryKey()
@@ -655,7 +656,7 @@ describe("useQuery's in Suspense mode", () => {
655
656
  })
656
657
 
657
658
  it('should throw errors to the error boundary when a throwErrors function returns true', async () => {
658
- const consoleMock = jest
659
+ const consoleMock = vi
659
660
  .spyOn(console, 'error')
660
661
  .mockImplementation(() => undefined)
661
662
  const key = queryKey()
@@ -739,7 +740,7 @@ describe("useQuery's in Suspense mode", () => {
739
740
  it('should not call the queryFn when not enabled', async () => {
740
741
  const key = queryKey()
741
742
 
742
- const queryFn = jest.fn<Promise<string>, unknown[]>()
743
+ const queryFn = vi.fn<unknown[], Promise<string>>()
743
744
  queryFn.mockImplementation(async () => {
744
745
  await sleep(10)
745
746
  return '23'
@@ -781,7 +782,7 @@ describe("useQuery's in Suspense mode", () => {
781
782
  })
782
783
 
783
784
  it('should error catched in error boundary without infinite loop', async () => {
784
- const consoleMock = jest
785
+ const consoleMock = vi
785
786
  .spyOn(console, 'error')
786
787
  .mockImplementation(() => undefined)
787
788
  const key = queryKey()
@@ -854,7 +855,7 @@ describe("useQuery's in Suspense mode", () => {
854
855
  })
855
856
 
856
857
  it('should error catched in error boundary without infinite loop when query keys changed', async () => {
857
- const consoleMock = jest
858
+ const consoleMock = vi
858
859
  .spyOn(console, 'error')
859
860
  .mockImplementation(() => undefined)
860
861
  let succeed = true
@@ -921,7 +922,7 @@ describe("useQuery's in Suspense mode", () => {
921
922
  })
922
923
 
923
924
  it('should error catched in error boundary without infinite loop when enabled changed', async () => {
924
- const consoleMock = jest
925
+ const consoleMock = vi
925
926
  .spyOn(console, 'error')
926
927
  .mockImplementation(() => undefined)
927
928
  function Page() {
@@ -14,6 +14,8 @@ import type {
14
14
  UseInfiniteQueryResult,
15
15
  } from '..'
16
16
  import { QueryCache, useInfiniteQuery, keepPreviousData } from '..'
17
+ import { vi } from 'vitest'
18
+ import type { Mock } from 'vitest'
17
19
 
18
20
  interface Result {
19
21
  items: number[]
@@ -680,14 +682,14 @@ describe('useInfiniteQuery', () => {
680
682
  it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => {
681
683
  const key = queryKey()
682
684
  const start = 10
683
- const onAborts: jest.Mock<any, any>[] = []
684
- const abortListeners: jest.Mock<any, any>[] = []
685
- const fetchPage = jest.fn<
686
- Promise<number>,
687
- [QueryFunctionContext<typeof key, number>]
685
+ const onAborts: Mock<any, any>[] = []
686
+ const abortListeners: Mock<any, any>[] = []
687
+ const fetchPage = vi.fn<
688
+ [QueryFunctionContext<typeof key, number>],
689
+ Promise<number>
688
690
  >(async ({ pageParam, signal }) => {
689
- const onAbort = jest.fn()
690
- const abortListener = jest.fn()
691
+ const onAbort = vi.fn()
692
+ const abortListener = vi.fn()
691
693
  onAborts.push(onAbort)
692
694
  abortListeners.push(abortListener)
693
695
  signal.onabort = onAbort
@@ -756,14 +758,14 @@ describe('useInfiniteQuery', () => {
756
758
  it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
757
759
  const key = queryKey()
758
760
  const start = 10
759
- const onAborts: jest.Mock<any, any>[] = []
760
- const abortListeners: jest.Mock<any, any>[] = []
761
- const fetchPage = jest.fn<
762
- Promise<number>,
763
- [QueryFunctionContext<typeof key, number>]
761
+ const onAborts: Mock<any, any>[] = []
762
+ const abortListeners: Mock<any, any>[] = []
763
+ const fetchPage = vi.fn<
764
+ [QueryFunctionContext<typeof key, number>],
765
+ Promise<number>
764
766
  >(async ({ pageParam, signal }) => {
765
- const onAbort = jest.fn()
766
- const abortListener = jest.fn()
767
+ const onAbort = vi.fn()
768
+ const abortListener = vi.fn()
767
769
  onAborts.push(onAbort)
768
770
  abortListeners.push(abortListener)
769
771
  signal.onabort = onAbort
@@ -1491,11 +1493,11 @@ describe('useInfiniteQuery', () => {
1491
1493
 
1492
1494
  it('should cancel the query function when there are no more subscriptions', async () => {
1493
1495
  const key = queryKey()
1494
- let cancelFn: jest.Mock = jest.fn()
1496
+ let cancelFn: Mock = vi.fn()
1495
1497
 
1496
1498
  const queryFn = ({ signal }: { signal?: AbortSignal }) => {
1497
1499
  const promise = new Promise<string>((resolve, reject) => {
1498
- cancelFn = jest.fn(() => reject('Cancelled'))
1500
+ cancelFn = vi.fn(() => reject('Cancelled'))
1499
1501
  signal?.addEventListener('abort', cancelFn)
1500
1502
  sleep(1000).then(() => resolve('OK'))
1501
1503
  })
@@ -60,7 +60,6 @@ describe('pageParam', () => {
60
60
  })
61
61
  })
62
62
  })
63
-
64
63
  describe('select', () => {
65
64
  it('should still return paginated data if no select result', () => {
66
65
  doNotExecute(() => {
@@ -129,3 +128,84 @@ describe('select', () => {
129
128
  })
130
129
  })
131
130
  })
131
+ describe('getNextPageParam / getPreviousPageParam', () => {
132
+ it('should get typed params', () => {
133
+ doNotExecute(() => {
134
+ const infiniteQuery = useInfiniteQuery({
135
+ queryKey: ['key'],
136
+ queryFn: ({ pageParam }) => {
137
+ return String(pageParam)
138
+ },
139
+ defaultPageParam: 1,
140
+ getNextPageParam: (
141
+ lastPage,
142
+ allPages,
143
+ lastPageParam,
144
+ allPageParams,
145
+ ) => {
146
+ doNotExecute(() => {
147
+ const lastPageResult: Expect<Equal<string, typeof lastPage>> = true
148
+ return lastPageResult
149
+ })
150
+ doNotExecute(() => {
151
+ const allPagesResult: Expect<
152
+ Equal<Array<string>, typeof allPages>
153
+ > = true
154
+ return allPagesResult
155
+ })
156
+ doNotExecute(() => {
157
+ const lastPageParamResult: Expect<
158
+ Equal<number, typeof lastPageParam>
159
+ > = true
160
+ return lastPageParamResult
161
+ })
162
+ doNotExecute(() => {
163
+ const allPageParamsResult: Expect<
164
+ Equal<Array<number>, typeof allPageParams>
165
+ > = true
166
+ return allPageParamsResult
167
+ })
168
+
169
+ return undefined
170
+ },
171
+ getPreviousPageParam: (
172
+ firstPage,
173
+ allPages,
174
+ firstPageParam,
175
+ allPageParams,
176
+ ) => {
177
+ doNotExecute(() => {
178
+ const firstPageResult: Expect<Equal<string, typeof firstPage>> =
179
+ true
180
+ return firstPageResult
181
+ })
182
+ doNotExecute(() => {
183
+ const allPagesResult: Expect<
184
+ Equal<Array<string>, typeof allPages>
185
+ > = true
186
+ return allPagesResult
187
+ })
188
+ doNotExecute(() => {
189
+ const firstPageParamResult: Expect<
190
+ Equal<number, typeof firstPageParam>
191
+ > = true
192
+ return firstPageParamResult
193
+ })
194
+ doNotExecute(() => {
195
+ const allPageParamsResult: Expect<
196
+ Equal<Array<number>, typeof allPageParams>
197
+ > = true
198
+ return allPageParamsResult
199
+ })
200
+
201
+ return undefined
202
+ },
203
+ })
204
+
205
+ const result: Expect<
206
+ Equal<InfiniteData<string> | undefined, (typeof infiniteQuery)['data']>
207
+ > = true
208
+ return result
209
+ })
210
+ })
211
+ })
@@ -13,6 +13,7 @@ import {
13
13
  setActTimeout,
14
14
  sleep,
15
15
  } from './utils'
16
+ import { vi } from 'vitest'
16
17
 
17
18
  describe('useMutation', () => {
18
19
  const queryCache = new QueryCache()
@@ -95,8 +96,8 @@ describe('useMutation', () => {
95
96
 
96
97
  it('should be able to call `onSuccess` and `onSettled` after each successful mutate', async () => {
97
98
  let count = 0
98
- const onSuccessMock = jest.fn()
99
- const onSettledMock = jest.fn()
99
+ const onSuccessMock = vi.fn()
100
+ const onSettledMock = vi.fn()
100
101
 
101
102
  function Page() {
102
103
  const { mutate } = useMutation({
@@ -151,7 +152,7 @@ describe('useMutation', () => {
151
152
  let count = 0
152
153
  type Value = { count: number }
153
154
 
154
- const mutateFn = jest.fn<Promise<Value>, [value: Value]>()
155
+ const mutateFn = vi.fn<[value: Value], Promise<Value>>()
155
156
 
156
157
  mutateFn.mockImplementationOnce(() => {
157
158
  return Promise.reject(new Error('Error test Jonas'))
@@ -197,8 +198,8 @@ describe('useMutation', () => {
197
198
  })
198
199
 
199
200
  it('should be able to call `onError` and `onSettled` after each failed mutate', async () => {
200
- const onErrorMock = jest.fn()
201
- const onSettledMock = jest.fn()
201
+ const onErrorMock = vi.fn()
202
+ const onSettledMock = vi.fn()
202
203
  let count = 0
203
204
 
204
205
  function Page() {
@@ -488,7 +489,7 @@ describe('useMutation', () => {
488
489
 
489
490
  it('should call onMutate even if paused', async () => {
490
491
  const onlineMock = mockNavigatorOnLine(false)
491
- const onMutate = jest.fn()
492
+ const onMutate = vi.fn()
492
493
  let count = 0
493
494
 
494
495
  function Page() {
@@ -688,7 +689,7 @@ describe('useMutation', () => {
688
689
  })
689
690
 
690
691
  it('should be able to throw an error when throwErrors is set to true', async () => {
691
- const consoleMock = jest
692
+ const consoleMock = vi
692
693
  .spyOn(console, 'error')
693
694
  .mockImplementation(() => undefined)
694
695
  function Page() {
@@ -735,7 +736,7 @@ describe('useMutation', () => {
735
736
  })
736
737
 
737
738
  it('should be able to throw an error when throwErrors is a function that returns true', async () => {
738
- const consoleMock = jest
739
+ const consoleMock = vi
739
740
  .spyOn(console, 'error')
740
741
  .mockImplementation(() => undefined)
741
742
  let boundary = false
@@ -788,8 +789,8 @@ describe('useMutation', () => {
788
789
  })
789
790
 
790
791
  it('should pass meta to mutation', async () => {
791
- const errorMock = jest.fn()
792
- const successMock = jest.fn()
792
+ const errorMock = vi.fn()
793
+ const successMock = vi.fn()
793
794
 
794
795
  const queryClientMutationMeta = createQueryClient({
795
796
  mutationCache: new MutationCache({
@@ -847,10 +848,10 @@ describe('useMutation', () => {
847
848
  })
848
849
 
849
850
  it('should call cache callbacks when unmounted', async () => {
850
- const onSuccess = jest.fn()
851
- const onSuccessMutate = jest.fn()
852
- const onSettled = jest.fn()
853
- const onSettledMutate = jest.fn()
851
+ const onSuccess = vi.fn()
852
+ const onSuccessMutate = vi.fn()
853
+ const onSettled = vi.fn()
854
+ const onSettledMutate = vi.fn()
854
855
  const mutationKey = queryKey()
855
856
  let count = 0
856
857
 
@@ -919,10 +920,10 @@ describe('useMutation', () => {
919
920
  })
920
921
 
921
922
  it('should call mutate callbacks only for the last observer', async () => {
922
- const onSuccess = jest.fn()
923
- const onSuccessMutate = jest.fn()
924
- const onSettled = jest.fn()
925
- const onSettledMutate = jest.fn()
923
+ const onSuccess = vi.fn()
924
+ const onSuccessMutate = vi.fn()
925
+ const onSettled = vi.fn()
926
+ const onSettledMutate = vi.fn()
926
927
  let count = 0
927
928
 
928
929
  function Page() {
@@ -1008,7 +1009,7 @@ describe('useMutation', () => {
1008
1009
 
1009
1010
  it('should go to error state if onSuccess callback errors', async () => {
1010
1011
  const error = new Error('error from onSuccess')
1011
- const onError = jest.fn()
1012
+ const onError = vi.fn()
1012
1013
 
1013
1014
  function Page() {
1014
1015
  const mutation = useMutation({
@@ -1076,7 +1077,7 @@ describe('useMutation', () => {
1076
1077
  it('should go to error state if onSettled callback errors', async () => {
1077
1078
  const error = new Error('error from onSettled')
1078
1079
  const mutateFnError = new Error('mutateFnError')
1079
- const onError = jest.fn()
1080
+ const onError = vi.fn()
1080
1081
 
1081
1082
  function Page() {
1082
1083
  const mutation = useMutation({