2023-02-02 20:30:57 +01:00
|
|
|
import log from 'loglevel';
|
|
|
|
import { isErrorWithMessage, logErrorWithMessage } from './error';
|
|
|
|
|
|
|
|
jest.mock('loglevel');
|
|
|
|
|
|
|
|
describe('error module', () => {
|
2023-03-30 20:42:38 +02:00
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-02-02 20:30:57 +01:00
|
|
|
describe('isErrorWithMessage', () => {
|
|
|
|
it('returns true when passed an instance of an Error', () => {
|
|
|
|
expect(isErrorWithMessage(new Error('test'))).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when passed a string', () => {
|
|
|
|
expect(isErrorWithMessage('test')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('logErrorWithMessage', () => {
|
|
|
|
it('calls loglevel.error with the error.message when passed an instance of Error', () => {
|
|
|
|
logErrorWithMessage(new Error('test'));
|
2023-03-30 20:42:38 +02:00
|
|
|
expect(log.error).toHaveBeenCalledWith('test');
|
2023-02-02 20:30:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('calls loglevel.error with the parameter passed in when parameter is not an instance of Error', () => {
|
|
|
|
logErrorWithMessage({ test: 'test' });
|
2023-03-30 20:42:38 +02:00
|
|
|
expect(log.error).toHaveBeenCalledWith({ test: 'test' });
|
2023-02-02 20:30:57 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|