Skip to content

Commit

Permalink
Merge pull request #2958 from OliverRadini/issues/2934
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Nov 29, 2022
2 parents 026221a + 7f9a52a commit 1f78b68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const retryWithBackoff: BaseQueryEnhancer<
5,
((defaultOptions as any) || EMPTY_OPTIONS).maxRetries,
((extraOptions as any) || EMPTY_OPTIONS).maxRetries,
].filter(Boolean)
].filter(x => x !== undefined)
const [maxRetries] = possibleMaxRetries.slice(-1)

const defaultRetryCondition: RetryConditionFunction = (_, __, { attempt }) =>
Expand Down
27 changes: 27 additions & 0 deletions packages/toolkit/src/query/tests/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,33 @@ describe('configuration', () => {
expect(baseBaseQuery).toHaveBeenCalledTimes(4)
})

test('Specifying maxRetries as 0 in RetryOptions prevents retries', async () => {
const baseBaseQuery = jest.fn<
ReturnType<BaseQueryFn>,
Parameters<BaseQueryFn>
>()
baseBaseQuery.mockResolvedValue({ error: 'rejected' })

const baseQuery = retry(baseBaseQuery, { maxRetries: 0 })
const api = createApi({
baseQuery,
endpoints: (build) => ({
q1: build.query({
query: () => {},
}),
}),
})

const storeRef = setupApiStore(api, undefined, {
withoutTestLifecycles: true,
})

storeRef.store.dispatch(api.endpoints.q1.initiate({}))
await loopTimers(2)

expect(baseBaseQuery).toHaveBeenCalledTimes(1)
});

test.skip('RetryOptions only accepts one of maxRetries or retryCondition', () => {
// @ts-expect-error Should complain if both exist at once
const ro: RetryOptions = {
Expand Down

0 comments on commit 1f78b68

Please sign in to comment.