Skip to content

Commit

Permalink
verify and report invalid options with stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
matmar10 committed Jun 16, 2020
1 parent 3f4e2f8 commit 0de1b40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/object-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function assertValidateOptions(options) {
const ajv = new Ajv({ allErrors: true });
const valid = ajv.validate(optionsSchema, options);
if (!valid) {
throw new Ajv.ValidationError(ajv.errors);
const err = new Error('Invalid options for ObjectMapper');
err.errors = ajv.errors;
throw err;
}
}

Expand Down
19 changes: 14 additions & 5 deletions test/mapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ const TruffleConfig = require('@truffle/config');
const deployedAddress = '0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B';

describe('Mapper', function () {
let mapper;

before(function () {
mapper = new Mapper({
workingDirectory: __dirname,
describe('constructor', function () {
it('rejects invalid options', function () {
chai.expect(() => {
new Mapper({
workingDirectory: {},
});
}).to.throw();
});
});

describe('map', function () {
let mapper;
before(function () {
mapper = new Mapper({
workingDirectory: __dirname,
});
});

it('uses defaults', async function () {
const values = await mapper.map('MetaCoin', deployedAddress);
chai.expect(values).to.have.property('bytes32Example', 'bytes 32 example');
Expand Down

0 comments on commit 0de1b40

Please sign in to comment.