Skip to content

Commit 08c32a7

Browse files
committed
feat: mutation cachetime
try to make tests more resilient
1 parent d10cad0 commit 08c32a7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/core/tests/mutationCache.test.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ describe('mutationCache', () => {
123123

124124
expect(testCache.getAll()).toHaveLength(1)
125125
await sleep(10)
126-
expect(testCache.getAll()).toHaveLength(0)
126+
await waitFor(() => {
127+
expect(testCache.getAll()).toHaveLength(0)
128+
})
127129
expect(onSuccess).toHaveBeenCalledTimes(1)
128130
})
129131

@@ -144,7 +146,9 @@ describe('mutationCache', () => {
144146
unsubscribe()
145147
expect(queryClient.getMutationCache().getAll()).toHaveLength(1)
146148
await sleep(10)
147-
expect(queryClient.getMutationCache().getAll()).toHaveLength(0)
149+
await waitFor(() => {
150+
expect(queryClient.getMutationCache().getAll()).toHaveLength(0)
151+
})
148152
})
149153

150154
test('should only remove when the last observer unsubscribes', async () => {
@@ -182,7 +186,9 @@ describe('mutationCache', () => {
182186
expect(queryClient.getMutationCache().getAll()).toHaveLength(1)
183187
// wait for cacheTime to gc
184188
await sleep(10)
185-
expect(queryClient.getMutationCache().getAll()).toHaveLength(0)
189+
await waitFor(() => {
190+
expect(queryClient.getMutationCache().getAll()).toHaveLength(0)
191+
})
186192
})
187193

188194
test('should be garbage collected later when unsubscribed and mutation is loading', async () => {
@@ -206,7 +212,9 @@ describe('mutationCache', () => {
206212
expect(queryClient.getMutationCache().getAll()).toHaveLength(1)
207213
await sleep(10)
208214
// 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+
})
210218
expect(onSuccess).toHaveBeenCalledTimes(1)
211219
})
212220

0 commit comments

Comments
 (0)