1
- import { describe , expect , it , vi } from 'vitest'
2
- import { fireEvent , render , waitFor } from '@solidjs/testing-library'
1
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
2
+ import { fireEvent , render } from '@solidjs/testing-library'
3
3
import { Show , createEffect , createRenderEffect , createSignal } from 'solid-js'
4
4
import * as QueryCore from '@tanstack/query-core'
5
5
import { sleep } from '@tanstack/query-test-utils'
@@ -12,6 +12,14 @@ import {
12
12
import { setActTimeout } from './utils'
13
13
14
14
describe ( 'useIsMutating' , ( ) => {
15
+ beforeEach ( ( ) => {
16
+ vi . useFakeTimers ( )
17
+ } )
18
+
19
+ afterEach ( ( ) => {
20
+ vi . useRealTimers ( )
21
+ } )
22
+
15
23
it ( 'should return the number of fetching mutations' , async ( ) => {
16
24
const isMutatingArray : Array < number > = [ ]
17
25
const queryClient = new QueryClient ( )
@@ -64,7 +72,7 @@ describe('useIsMutating', () => {
64
72
< Page />
65
73
</ QueryClientProvider >
66
74
) )
67
- await waitFor ( ( ) => expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 2 , 1 , 0 ] ) )
75
+ await vi . waitFor ( ( ) => expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 2 , 1 , 0 ] ) )
68
76
} )
69
77
70
78
it ( 'should filter correctly by mutationKey' , async ( ) => {
@@ -109,7 +117,7 @@ describe('useIsMutating', () => {
109
117
</ QueryClientProvider >
110
118
) )
111
119
// Unlike React, IsMutating Wont re-render twice with mutation2
112
- await waitFor ( ( ) => expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 0 ] ) )
120
+ await vi . waitFor ( ( ) => expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 0 ] ) )
113
121
} )
114
122
115
123
it ( 'should filter correctly by predicate' , async ( ) => {
@@ -158,7 +166,7 @@ describe('useIsMutating', () => {
158
166
) )
159
167
160
168
// Again, No unnecessary re-renders like React
161
- await waitFor ( ( ) => expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 0 ] ) )
169
+ await vi . waitFor ( ( ) => expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 0 ] ) )
162
170
} )
163
171
164
172
it ( 'should use provided custom queryClient' , async ( ) => {
@@ -188,7 +196,7 @@ describe('useIsMutating', () => {
188
196
189
197
const rendered = render ( ( ) => < Page > </ Page > )
190
198
191
- await waitFor ( ( ) =>
199
+ await vi . waitFor ( ( ) =>
192
200
expect ( rendered . getByText ( 'mutating: 1' ) ) . toBeInTheDocument ( ) ,
193
201
)
194
202
} )
@@ -251,7 +259,7 @@ describe('useIsMutating', () => {
251
259
// Should not display the console error
252
260
// "Warning: Can't perform a React state update on an unmounted component"
253
261
254
- await sleep ( 20 )
262
+ await vi . advanceTimersByTimeAsync ( 20 )
255
263
MutationCacheSpy . mockRestore ( )
256
264
} )
257
265
} )
0 commit comments