ErrorMatcher.utils.test.ts34 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { getMappingForError } from './ErrorMatcher.utils' |
| 4 | import { ConnectionTimeoutError, UnknownAPIResponseError } from '@/types/api-errors' |
| 5 | |
| 6 | describe('getMappingForError', () => { |
| 7 | it('returns the mapping for a classified error with a known errorType', () => { |
| 8 | const error = new ConnectionTimeoutError('connection terminated due to connection timeout') |
| 9 | const mapping = getMappingForError(error) |
| 10 | expect(mapping).not.toBeNull() |
| 11 | expect(mapping?.id).toBe('connection-timeout') |
| 12 | }) |
| 13 | |
| 14 | it('returns null for UnknownAPIResponseError (no troubleshooting guide)', () => { |
| 15 | const error = new UnknownAPIResponseError('something went wrong') |
| 16 | expect(getMappingForError(error)).toBeNull() |
| 17 | }) |
| 18 | |
| 19 | it('returns null for a plain string', () => { |
| 20 | expect(getMappingForError('some error message')).toBeNull() |
| 21 | }) |
| 22 | |
| 23 | it('returns null for null', () => { |
| 24 | expect(getMappingForError(null)).toBeNull() |
| 25 | }) |
| 26 | |
| 27 | it('returns null for an object with no errorType', () => { |
| 28 | expect(getMappingForError({ message: 'error' })).toBeNull() |
| 29 | }) |
| 30 | |
| 31 | it('returns null for an object with an unrecognised errorType', () => { |
| 32 | expect(getMappingForError({ errorType: 'not-a-real-type' })).toBeNull() |
| 33 | }) |
| 34 | }) |