fix(tests): begin testing friendly errors, other errors (exceptions)
This commit is contained in:
parent
c9c1a58407
commit
a13a9095bc
4
Makefile
4
Makefile
|
@ -95,7 +95,9 @@ test-examples: ## run medium (feature) tests
|
|||
|
||||
test-bundle: ## run small (unit) tests
|
||||
test-bundle: build-bundle
|
||||
$(NODE_BIN)/nyc --reporter=lcov --reporter=text-summary --report-dir="$(TARGET_PATH)/coverage" --exclude-after-remap $(NODE_BIN)/mocha $(TARGET_PATH)/test.js
|
||||
$(NODE_BIN)/nyc --report-dir="$(TARGET_PATH)/coverage" --exclude-after-remap \
|
||||
--reporter=html --reporter=lcov --reporter=text-summary \
|
||||
$(NODE_BIN)/mocha $(TARGET_PATH)/test.js
|
||||
|
||||
test-rules: ## validate the rules directory
|
||||
test-rules: build-bundle
|
||||
|
|
|
@ -76,6 +76,7 @@ const bundle = {
|
|||
'intersection',
|
||||
'isNil',
|
||||
'isString',
|
||||
'kebabCase',
|
||||
],
|
||||
'node_modules/noicejs/out/main-bundle.js': [
|
||||
'BaseError',
|
||||
|
|
|
@ -74,7 +74,7 @@ export async function loadRules(paths: Array<string>, ctx: VisitorContext): Prom
|
|||
ctx.addSchema(data.name, data.definitions);
|
||||
}
|
||||
|
||||
rules.push(...data.rules.map((data: any) => new Rule(data)));
|
||||
rules.push(...data.rules.map((data: RuleData) => new Rule(data)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
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), () => {
|
||||
it('should have a message', () => {
|
||||
const err = new errorType();
|
||||
expect(err.message).to.not.equal('');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { friendlyError } from '../../../src/utils/ajv';
|
||||
|
||||
describe('friendly errors', () => {
|
||||
it('should have a message', () => {
|
||||
const err = friendlyError({
|
||||
keyword: 'test',
|
||||
dataPath: 'test-path',
|
||||
schemaPath: 'test-path',
|
||||
params: { /* ? */ },
|
||||
});
|
||||
expect(err.msg).to.not.equal('');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue