1
0
Fork 0
js-utils/test/error/TestError.ts

42 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-03-29 13:43:52 +00:00
import { expect } from 'chai';
2022-10-08 19:10:17 +00:00
import { ChildProcessError } from '../../src/error/ChildProcessError.js';
import { InvalidArgumentError } from '../../src/error/InvalidArgumentError.js';
import { MissingKeyError } from '../../src/error/MissingKeyError.js';
import { NotFoundError } from '../../src/error/NotFoundError.js';
import { NotImplementedError } from '../../src/error/NotImplementedError.js';
import { TimeoutError } from '../../src/error/TimeoutError.js';
2020-03-29 13:43:52 +00:00
const errors = [
ChildProcessError,
InvalidArgumentError,
MissingKeyError,
NotFoundError,
NotImplementedError,
TimeoutError,
];
describe('errors', () => {
for (const errorType of errors) {
describe(errorType.name, () => {
2022-10-08 19:10:17 +00:00
it('should have a message', async () => {
2020-03-29 13:43:52 +00:00
const err = new errorType();
expect(err.message).to.not.equal('');
});
2022-10-08 19:10:17 +00:00
it('should include nested errors in the stack trace', async () => {
2020-03-29 13:43:52 +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');
});
2022-10-08 19:10:17 +00:00
it('should have the nested error', async () => {
2020-03-29 13:43:52 +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);
});
});
}
});