Skip to content

Commit 0213506

Browse files
kahirokunnmarkerikson
authored andcommitted
test: retryCondition with endpoint config that overrides baseQuery config
1 parent 79351f4 commit 0213506

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
@@ -371,4 +371,36 @@ describe('configuration', () => {
371371

372372
expect(baseBaseQuery).toHaveBeenCalledTimes(overrideMaxRetries + 1)
373373
})
374+
375+
test('retryCondition with endpoint config that overrides baseQuery config', async () => {
376+
const baseBaseQuery = jest.fn<
377+
ReturnType<BaseQueryFn>,
378+
Parameters<BaseQueryFn>
379+
>()
380+
baseBaseQuery.mockResolvedValue({ error: 'rejected' })
381+
382+
const baseQuery = retry(baseBaseQuery, {
383+
maxRetries: 10
384+
})
385+
const api = createApi({
386+
baseQuery,
387+
endpoints: (build) => ({
388+
q1: build.query({
389+
query: () => {},
390+
extraOptions: {
391+
retryCondition: (_, __, {attempt, maxRetries}) => attempt <= maxRetries / 2,
392+
}
393+
}),
394+
}),
395+
})
396+
397+
const storeRef = setupApiStore(api, undefined, {
398+
withoutTestLifecycles: true,
399+
})
400+
storeRef.store.dispatch(api.endpoints.q1.initiate({}))
401+
402+
await loopTimers()
403+
404+
expect(baseBaseQuery).toHaveBeenCalledTimes(6)
405+
})
374406
})

0 commit comments

Comments
 (0)