@@ -20,7 +20,9 @@ describe('useIsMutating', () => {
20
20
21
21
function IsMutating ( ) {
22
22
const isMutating = useIsMutating ( )
23
+
23
24
isMutatingArray . push ( isMutating )
25
+
24
26
return null
25
27
}
26
28
@@ -52,6 +54,7 @@ describe('useIsMutating', () => {
52
54
}
53
55
54
56
const rendered = renderWithClient ( queryClient , < Page /> )
57
+
55
58
fireEvent . click ( rendered . getByRole ( 'button' , { name : / m u t a t e 1 / i } ) )
56
59
await vi . advanceTimersByTimeAsync ( 10 )
57
60
fireEvent . click ( rendered . getByRole ( 'button' , { name : / m u t a t e 2 / i } ) )
@@ -62,12 +65,14 @@ describe('useIsMutating', () => {
62
65
// [ +0, 1, 2, 1, +0 ]
63
66
// our batching strategy might yield different results
64
67
65
- await vi . advanceTimersByTimeAsync ( 40 )
68
+ await vi . advanceTimersByTimeAsync ( 41 )
66
69
expect ( isMutatingArray [ 0 ] ) . toEqual ( 0 )
67
70
expect ( isMutatingArray [ 1 ] ) . toEqual ( 1 )
68
71
expect ( isMutatingArray [ 2 ] ) . toEqual ( 2 )
69
- await vi . advanceTimersByTimeAsync ( 1 )
70
- expect ( isMutatingArray [ isMutatingArray . length - 1 ] ) . toEqual ( 0 )
72
+ expect ( isMutatingArray [ 3 ] ) . toEqual ( 1 )
73
+ expect ( isMutatingArray [ 4 ] ) . toEqual ( 0 )
74
+
75
+ expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 2 , 1 , 0 ] )
71
76
} )
72
77
73
78
it ( 'should filter correctly by mutationKey' , async ( ) => {
@@ -99,6 +104,7 @@ describe('useIsMutating', () => {
99
104
}
100
105
101
106
renderWithClient ( queryClient , < Page /> )
107
+
102
108
await vi . advanceTimersByTimeAsync ( 101 )
103
109
expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 0 ] )
104
110
} )
@@ -135,6 +141,7 @@ describe('useIsMutating', () => {
135
141
}
136
142
137
143
renderWithClient ( queryClient , < Page /> )
144
+
138
145
await vi . advanceTimersByTimeAsync ( 101 )
139
146
expect ( isMutatingArray ) . toEqual ( [ 0 , 1 , 0 ] )
140
147
} )
@@ -163,7 +170,7 @@ describe('useIsMutating', () => {
163
170
)
164
171
}
165
172
166
- const rendered = render ( < Page > </ Page > )
173
+ const rendered = render ( < Page / >)
167
174
168
175
await vi . advanceTimersByTimeAsync ( 0 )
169
176
expect ( rendered . getByText ( 'mutating: 1' ) ) . toBeInTheDocument ( )
@@ -220,12 +227,11 @@ describe('useMutationState', () => {
220
227
221
228
const rendered = renderWithClient ( queryClient , < Page /> )
222
229
223
- rendered . getByText ( 'data: null' )
230
+ expect ( rendered . getByText ( 'data: null' ) ) . toBeInTheDocument ( )
224
231
225
232
fireEvent . click ( rendered . getByRole ( 'button' , { name : / m u t a t e / i } ) )
226
-
227
233
await vi . advanceTimersByTimeAsync ( 151 )
228
- rendered . getByText ( 'data: data1' )
234
+ expect ( rendered . getByText ( 'data: data1' ) ) . toBeInTheDocument ( )
229
235
230
236
expect ( variables ) . toEqual ( [ [ ] , [ 1 ] , [ ] ] )
231
237
} )
0 commit comments