Skip to content

Commit 79351f4

Browse files
kahirokunnmarkerikson
authored andcommitted
test: accepts a custom retryCondition fn
1 parent 8959619 commit 79351f4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/toolkit/src/query/tests/retry.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,36 @@ describe('configuration', () => {
339339

340340
expect(baseBaseQuery).toHaveBeenCalledTimes(9)
341341
})
342+
343+
test('accepts a custom retryCondition fn', async () => {
344+
const baseBaseQuery = jest.fn<
345+
ReturnType<BaseQueryFn>,
346+
Parameters<BaseQueryFn>
347+
>()
348+
baseBaseQuery.mockResolvedValue({ error: 'rejected' })
349+
350+
const overrideMaxRetries = 3
351+
352+
const baseQuery = retry(baseBaseQuery, {
353+
maxRetries: 0,
354+
retryCondition: (_, __, {attempt}) => attempt <= overrideMaxRetries,
355+
})
356+
const api = createApi({
357+
baseQuery,
358+
endpoints: (build) => ({
359+
q1: build.query({
360+
query: () => {},
361+
}),
362+
}),
363+
})
364+
365+
const storeRef = setupApiStore(api, undefined, {
366+
withoutTestLifecycles: true,
367+
})
368+
storeRef.store.dispatch(api.endpoints.q1.initiate({}))
369+
370+
await loopTimers()
371+
372+
expect(baseBaseQuery).toHaveBeenCalledTimes(overrideMaxRetries + 1)
373+
})
342374
})

0 commit comments

Comments
 (0)