Skip to content

Commit

Permalink
test(react-client): add test to handle CancelError from the conversio…
Browse files Browse the repository at this point in the history
…n job poller
  • Loading branch information
nd0ut committed Jan 17, 2024
1 parent 83f10c6 commit 7dddbd2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/rest-client/src/tools/conversionJobPoller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { testSettings } from '../../test/helpers'
import { ConversionStatus } from '../types/ConversionStatus'
import { ConversionType } from '../types/ConversionType'
import { conversionJobPoller } from './conversionJobPoller'
import { delay } from '@uploadcare/api-client-utils'

jest.setTimeout(60 * 1000)

Expand Down Expand Up @@ -125,4 +126,31 @@ describe('conversionJobPoller', () => {
})
])
})

it('should be able to catch CancelError', async () => {
const path = `${DOCUMENT_UUID}/document/-/format/pdf/`

const abortController = new AbortController()

const promises = await conversionJobPoller(
{
type: ConversionType.DOCUMENT,
paths: [path],
store: false,
pollOptions: {
signal: abortController.signal
}
},
testSettings
)
await delay(0)
abortController.abort()

expect.assertions(3)
expect(promises.length).toBe(1)
await promises[0].catch((err) => {
expect(err.name).toBe('CancelError')
expect(err.isCancel).toBeTrue()
})
})
})

0 comments on commit 7dddbd2

Please sign in to comment.