import { assertNativeError, getStatusCode, isNativeError } from '../../../../src/util/errors/ErrorUtil'; import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError'; describe('ErrorUtil', (): void => { describe('#isNativeError', (): void => { it('returns true on native errors.', async(): Promise => { expect(isNativeError(new Error('error'))).toBe(true); }); it('returns false on other values.', async(): Promise => { expect(isNativeError('apple')).toBe(false); }); }); describe('#assertNativeError', (): void => { it('returns undefined on native errors.', async(): Promise => { expect(assertNativeError(new Error('error'))).toBeUndefined(); }); it('throws on other values.', async(): Promise => { expect((): void => assertNativeError('apple')).toThrow('apple'); }); }); describe('#getStatusCode', (): void => { it('returns the corresponding status code for HttpErrors.', async(): Promise => { expect(getStatusCode(new NotFoundHttpError())).toBe(404); }); it('returns 500 for other errors.', async(): Promise => { expect(getStatusCode(new Error('404'))).toBe(500); }); }); });