1
0
Fork 0
salty-dog/test/error/TestError.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

import { expect } from 'chai';
import { kebabCase } from 'lodash';
import { InvalidArgumentError } from '../../src/error/InvalidArgumentError';
import { NotFoundError } from '../../src/error/NotFoundError';
const errors = [
InvalidArgumentError,
NotFoundError,
];
describe('errors', () => {
for (const errorType of errors) {
describe(kebabCase(errorType.name), () => {
2019-09-30 13:17:49 +00:00
it('should have a message', () => {
const err = new errorType();
expect(err.message).to.not.equal('');
});
2019-09-30 13:17:49 +00:00
it('should include nested errors in the stack trace', () => {
const inner = new Error('inner error');
const err = new errorType('outer error', inner);
expect(err.stack).to.include('inner', 'inner error message').and.include('outer', 'outer error message');
});
2019-09-30 13:17:49 +00:00
it('should have the nested error', () => {
const inner = new Error('inner error');
const err = new errorType('outer error', inner);
expect(err.cause()).to.equal(inner);
expect(err.length).to.equal(1);
});
});
}
});