From 7dddbd20a646e909424365ded7912805590e93c1 Mon Sep 17 00:00:00 2001 From: nd0ut Date: Wed, 17 Jan 2024 21:12:27 +0800 Subject: [PATCH] test(react-client): add test to handle CancelError from the conversion job poller --- .../src/tools/conversionJobPoller.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/rest-client/src/tools/conversionJobPoller.test.ts b/packages/rest-client/src/tools/conversionJobPoller.test.ts index d264297ab..aa7be7e72 100644 --- a/packages/rest-client/src/tools/conversionJobPoller.test.ts +++ b/packages/rest-client/src/tools/conversionJobPoller.test.ts @@ -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) @@ -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() + }) + }) })