grafana/public/app/core/utils/errors.test.ts
Ashley Harrison f8d89eff56
Chore: fix type errors in tests (#63270)
* fix any's in tests

* fix more any's in tests

* more test type fixes

* fixing any's in tests part 3

* more test type fixes

* fixing test any's p5

* some tidy up

* fix template_srv
2023-02-14 16:46:42 +01:00

57 lines
1.7 KiB
TypeScript

import { FetchError } from '@grafana/runtime';
import { getMessageFromError } from 'app/core/utils/errors';
describe('errors functions', () => {
let message: string | null;
describe('when getMessageFromError gets an error string', () => {
beforeEach(() => {
message = getMessageFromError('error string');
});
it('should return the string', () => {
expect(message).toBe('error string');
});
});
describe('when getMessageFromError gets an error object with message field', () => {
beforeEach(() => {
message = getMessageFromError(new Error('error string'));
});
it('should return the message text', () => {
expect(message).toBe('error string');
});
});
describe('when getMessageFromError gets an error object with data.message field', () => {
beforeEach(() => {
message = getMessageFromError({ data: { message: 'error string' }, status: 500 } as FetchError);
});
it('should return the message text', () => {
expect(message).toBe('error string');
});
});
describe('when getMessageFromError gets an error object with statusText field', () => {
beforeEach(() => {
message = getMessageFromError({ data: 'foo', statusText: 'error string', status: 500 } as FetchError);
});
it('should return the statusText text', () => {
expect(message).toBe('error string');
});
});
describe('when getMessageFromError gets an error object', () => {
beforeEach(() => {
message = getMessageFromError({ customError: 'error string' });
});
it('should return the stringified error', () => {
expect(message).toBe('{"customError":"error string"}');
});
});
});