2019-09-11 01:22:28 +00:00
|
|
|
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', () => {
|
2019-09-11 01:22:28 +00:00
|
|
|
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', () => {
|
2019-09-11 01:22:28 +00:00
|
|
|
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', () => {
|
2019-09-11 01:22:28 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|