Skip to content

Commit

Permalink
test: retryCondition also works with mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed Jul 10, 2022
1 parent a962733 commit 6d87361
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/toolkit/src/query/tests/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,39 @@ describe('configuration', () => {

expect(baseBaseQuery).toHaveBeenCalledTimes(6)
})

test('retryCondition also works with mutations', async () => {
const baseBaseQuery = jest.fn<
ReturnType<BaseQueryFn>,
Parameters<BaseQueryFn>
>()

baseBaseQuery
.mockRejectedValueOnce(new Error('rejected'))
.mockRejectedValueOnce(new Error('hello retryCondition'))
.mockRejectedValueOnce(new Error('rejected'))
.mockResolvedValue({ error: 'hello retryCondition' })

const baseQuery = retry(baseBaseQuery, {})
const api = createApi({
baseQuery,
endpoints: (build) => ({
m1: build.mutation({
query: () => ({ method: 'PUT' }),
extraOptions: {
retryCondition: (e) => e.data === 'hello retryCondition',
}
}),
}),
})

const storeRef = setupApiStore(api, undefined, {
withoutTestLifecycles: true,
})
storeRef.store.dispatch(api.endpoints.m1.initiate({}))

await loopTimers()

expect(baseBaseQuery).toHaveBeenCalledTimes(4)
})
})

0 comments on commit 6d87361

Please sign in to comment.