ErrorMatcher.utils.test.ts 1.2 KB

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