Skip to content

Commit

Permalink
test(upload-client): add tests for being errors instance of Uploadcar…
Browse files Browse the repository at this point in the history
…eError
  • Loading branch information
nd0ut committed Dec 21, 2023
1 parent 7c03c3d commit 1245d58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/api-client-utils/src/CancelError.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { CancelError } from './CancelError'
import { UploadcareError } from './UploadcareError'

describe('CancelError', () => {
it('should have "isCancel" property with "true" value', async () => {
it('should have "isCancel" property with "true" value', () => {
const cancelError = new CancelError('Cancelled!')
expect(cancelError.isCancel).toBe(true)
})

it('should have default messgage', async () => {
it('should have default messgage', () => {
const cancelError = new CancelError()
expect(cancelError.message).toBe('Request canceled')
expect(cancelError.isCancel).toBe(true)
})

it('should be able to pass message', async () => {
it('should be able to pass message', () => {
const cancelError = new CancelError('Message')
expect(cancelError.message).toBe('Message')
expect(cancelError.isCancel).toBe(true)
})

it('should be instanceof UploadcareError', () => {
expect(new CancelError()).toBeInstanceOf(UploadcareError)
})
})
7 changes: 7 additions & 0 deletions packages/api-client-utils/src/NetworkError.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NetworkError } from './NetworkError'
import { UploadcareError } from './UploadcareError'

describe('NetworkError', () => {
it('should work', () => {
Expand All @@ -9,4 +10,10 @@ describe('NetworkError', () => {
expect(error instanceof NetworkError).toBeTruthy()
expect(error.originalProgressEvent).toBe(progressEvent)
})

it('should be instanceof UploadcareError', () => {
const progressEvent = new Event('ProgressEvent') as ProgressEvent
const error = new NetworkError(progressEvent)
expect(error).toBeInstanceOf(UploadcareError)
})
})
6 changes: 6 additions & 0 deletions packages/rest-client/src/tools/RestClientError.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RestClientError } from './RestClientError'
import { Request, Response } from '../lib/fetch/fetch.node'
import { UploadcareError } from '@uploadcare/api-client-utils'

describe('RestClientError', () => {
it('should work', () => {
Expand Down Expand Up @@ -65,4 +66,9 @@ describe('RestClientError', () => {

expect(error.message).toBe('[200] OK')
})

it('should be instanceof UploadcareError', () => {
const error = new RestClientError()
expect(error).toBeInstanceOf(UploadcareError)
})
})
6 changes: 6 additions & 0 deletions packages/upload-client/test/tools/UploadError.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UploadcareError } from '@uploadcare/api-client-utils'
import { UploadError } from '../../src/tools/UploadError'

describe('UploadError', () => {
Expand Down Expand Up @@ -25,4 +26,9 @@ describe('UploadError', () => {

expect(error.stack).toBeDefined()
})

it('should be instanceof UploadcareError', () => {
const error = new UploadError('test error')
expect(error).toBeInstanceOf(UploadcareError)
})
})

0 comments on commit 1245d58

Please sign in to comment.