|
1 | 1 | import { MeiliSearch } from './utils/meilisearch-test-utils' |
2 | | -import { MeiliSearchApiError } from '../src/errors' |
| 2 | +import { |
| 3 | + MeiliSearchError, |
| 4 | + MeiliSearchApiError, |
| 5 | + MeiliSearchCommunicationError, |
| 6 | + MeiliSearchTimeOutError, |
| 7 | +} from '../src/errors' |
3 | 8 | import 'jest-fetch-mock' |
4 | 9 | import fetchMock from 'jest-fetch-mock' |
5 | 10 |
|
@@ -42,4 +47,51 @@ describe('Test on updates', () => { |
42 | 47 | expect(e.name).toEqual('MeiliSearchApiError') |
43 | 48 | } |
44 | 49 | }) |
| 50 | + |
| 51 | + test('MeiliSearchApiError can be compared with the instanceof operator', async () => { |
| 52 | + fetchMock.mockReject( |
| 53 | + new MeiliSearchApiError( |
| 54 | + { |
| 55 | + message: 'Some error', |
| 56 | + code: 'some_error', |
| 57 | + type: 'random_error', |
| 58 | + link: 'a link', |
| 59 | + }, |
| 60 | + 404 |
| 61 | + ) |
| 62 | + ) |
| 63 | + |
| 64 | + const client = new MeiliSearch({ host: 'http://localhost:9345' }) |
| 65 | + try { |
| 66 | + await client.health() |
| 67 | + } catch (e: any) { |
| 68 | + expect(e instanceof MeiliSearchApiError).toEqual(true) |
| 69 | + } |
| 70 | + }) |
| 71 | + |
| 72 | + test('MeiliSearchCommunicationError can be compared with the instanceof operator', async () => { |
| 73 | + fetchMock.mockReject(new Error('fake error message')) |
| 74 | + const client = new MeiliSearch({ host: 'http://localhost:9345' }) |
| 75 | + try { |
| 76 | + await client.health() |
| 77 | + } catch (e: any) { |
| 78 | + expect(e instanceof MeiliSearchCommunicationError).toEqual(true) |
| 79 | + } |
| 80 | + }) |
| 81 | + |
| 82 | + test('MeiliSearchError can be compared with the instanceof operator', () => { |
| 83 | + try { |
| 84 | + throw new MeiliSearchError('message') |
| 85 | + } catch (e: any) { |
| 86 | + expect(e instanceof MeiliSearchError).toEqual(true) |
| 87 | + } |
| 88 | + }) |
| 89 | + |
| 90 | + test('MeiliSearchTimeOutError can be compared with the instanceof operator', () => { |
| 91 | + try { |
| 92 | + throw new MeiliSearchTimeOutError('message') |
| 93 | + } catch (e: any) { |
| 94 | + expect(e instanceof MeiliSearchTimeOutError).toEqual(true) |
| 95 | + } |
| 96 | + }) |
45 | 97 | }) |
0 commit comments