1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/shared/modules/error.test.ts
Brad Decker c1f9c778c9
Add error module for safely handling errors (#17511)
Co-authored-by: Danica Shen <zhaodanica@gmail.com>
2023-02-02 13:30:57 -06:00

33 lines
975 B
TypeScript

import log from 'loglevel';
import { isErrorWithMessage, logErrorWithMessage } from './error';
jest.mock('loglevel');
afterEach(() => {
jest.resetAllMocks();
});
describe('error module', () => {
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'));
expect(log.error).toBeCalledWith('test');
});
it('calls loglevel.error with the parameter passed in when parameter is not an instance of Error', () => {
logErrorWithMessage({ test: 'test' });
expect(log.error).toBeCalledWith({ test: 'test' });
});
});
});