Skip to content

Commit 30d402e

Browse files
kahirokunnmarkerikson
authored andcommitted
test: retryCondition also works with mutations
1 parent 0213506 commit 30d402e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,39 @@ describe('configuration', () => {
403403

404404
expect(baseBaseQuery).toHaveBeenCalledTimes(6)
405405
})
406+
407+
test('retryCondition also works with mutations', async () => {
408+
const baseBaseQuery = jest.fn<
409+
ReturnType<BaseQueryFn>,
410+
Parameters<BaseQueryFn>
411+
>()
412+
413+
baseBaseQuery
414+
.mockRejectedValueOnce(new Error('rejected'))
415+
.mockRejectedValueOnce(new Error('hello retryCondition'))
416+
.mockRejectedValueOnce(new Error('rejected'))
417+
.mockResolvedValue({ error: 'hello retryCondition' })
418+
419+
const baseQuery = retry(baseBaseQuery, {})
420+
const api = createApi({
421+
baseQuery,
422+
endpoints: (build) => ({
423+
m1: build.mutation({
424+
query: () => ({ method: 'PUT' }),
425+
extraOptions: {
426+
retryCondition: (e) => e.data === 'hello retryCondition',
427+
}
428+
}),
429+
}),
430+
})
431+
432+
const storeRef = setupApiStore(api, undefined, {
433+
withoutTestLifecycles: true,
434+
})
435+
storeRef.store.dispatch(api.endpoints.m1.initiate({}))
436+
437+
await loopTimers()
438+
439+
expect(baseBaseQuery).toHaveBeenCalledTimes(4)
440+
})
406441
})

0 commit comments

Comments
 (0)