@@ -123,7 +123,9 @@ describe('mutationCache', () => {
123
123
124
124
expect ( testCache . getAll ( ) ) . toHaveLength ( 1 )
125
125
await sleep ( 10 )
126
- expect ( testCache . getAll ( ) ) . toHaveLength ( 0 )
126
+ await waitFor ( ( ) => {
127
+ expect ( testCache . getAll ( ) ) . toHaveLength ( 0 )
128
+ } )
127
129
expect ( onSuccess ) . toHaveBeenCalledTimes ( 1 )
128
130
} )
129
131
@@ -144,7 +146,9 @@ describe('mutationCache', () => {
144
146
unsubscribe ( )
145
147
expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 1 )
146
148
await sleep ( 10 )
147
- expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 0 )
149
+ await waitFor ( ( ) => {
150
+ expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 0 )
151
+ } )
148
152
} )
149
153
150
154
test ( 'should only remove when the last observer unsubscribes' , async ( ) => {
@@ -182,7 +186,9 @@ describe('mutationCache', () => {
182
186
expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 1 )
183
187
// wait for cacheTime to gc
184
188
await sleep ( 10 )
185
- expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 0 )
189
+ await waitFor ( ( ) => {
190
+ expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 0 )
191
+ } )
186
192
} )
187
193
188
194
test ( 'should be garbage collected later when unsubscribed and mutation is loading' , async ( ) => {
@@ -206,7 +212,9 @@ describe('mutationCache', () => {
206
212
expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 1 )
207
213
await sleep ( 10 )
208
214
// should be removed after an additional cacheTime wait
209
- expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 0 )
215
+ await waitFor ( ( ) => {
216
+ expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 0 )
217
+ } )
210
218
expect ( onSuccess ) . toHaveBeenCalledTimes ( 1 )
211
219
} )
212
220
0 commit comments