1
0
Fork 0

fix(tests): begin testing friendly errors, other errors (exceptions)

This commit is contained in:
ssube 2019-09-10 20:22:28 -05:00 committed by Sean Sube
parent c9c1a58407
commit a13a9095bc
5 changed files with 54 additions and 2 deletions

View File

@ -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

View File

@ -76,6 +76,7 @@ const bundle = {
'intersection',
'isNil',
'isString',
'kebabCase',
],
'node_modules/noicejs/out/main-bundle.js': [
'BaseError',

View File

@ -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)));
}
}

34
test/error/TestError.ts Normal file
View File

@ -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);
});
});
}
});

View File

@ -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('');
});
});