Files
grafana/public/app/features/alerting/unified/utils/messageFromError.test.ts
Tom Ratcliffe 4f7ffafe98 Alerting: Consistently order member imports in alerting code (#97688)
* Lint import member orders within alerting

* Consistently order member imports in alerting code
2024-12-10 17:42:33 +00:00

36 lines
1.1 KiB
TypeScript

import { FetchError } from '@grafana/runtime';
import { UNKNOW_ERROR, messageFromError } from './redux';
describe('messageFromError method', () => {
it('should return UNKNOW_ERROR message when error is an object and not having neither in the e.data.message and nor in e.message', () => {
const error: FetchError = {
config: {
url: '',
},
data: { message: '', error: '', response: '' },
status: 502,
statusText: '',
};
expect(messageFromError(error)).toBe(UNKNOW_ERROR);
});
it('should return correct message in case of having message info in the e object (in e.data.message or in e.message)', () => {
const error: FetchError = {
config: {
url: '',
},
data: { message: 'BLA BLA', error: 'this is the error', response: '' },
status: 502,
statusText: 'BLu BLu',
};
expect(messageFromError(error)).toBe('BLA BLA; this is the error');
const error2: Error = {
name: 'bla bla',
message: 'THIS IS THE MESSAGE ERROR',
};
expect(messageFromError(error2)).toBe('THIS IS THE MESSAGE ERROR');
});
});