Skip to content

Commit

Permalink
feat: add two more tests of the cancel method
Browse files Browse the repository at this point in the history
  • Loading branch information
vmlopezr committed Feb 3, 2021
1 parent c6346c0 commit 9612292
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,20 @@ function standardTests(
expect(cancel).not.toHaveBeenCalled()
})

it('should cancel the outstanding request when the cancel method is called after the component rerenders with same config', async () => {
axios.mockResolvedValue({ data: 'whatever' })

const { waitForNextUpdate, rerender, result } = setup('initial config')

await waitForNextUpdate()

rerender()

result.current[2]()

expect(cancel).toHaveBeenCalled()
})

it('should not dispatch an error when the request is canceled', async () => {
const cancellation = new Error('canceled')

Expand Down Expand Up @@ -517,6 +531,22 @@ function standardTests(
await waitForNextUpdate()
})

it('should cancel the outstanding manual refetch when the cancel method is called', async () => {
axios.mockResolvedValue({ data: 'whatever' })

const { result, waitForNextUpdate } = setup('', { manual: true })

act(() => {
result.current[1]()
})

await waitForNextUpdate()

result.current[2]()

expect(cancel).toHaveBeenCalled()
})

it('should throw an error when the request is canceled', async () => {
const cancellation = new Error('canceled')

Expand Down

0 comments on commit 9612292

Please sign in to comment.