Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix He committed Jul 13, 2020
1 parent ed06ad9 commit 11f644e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions spec/issues/1244_custom_validate_should_skip_extenderrors.spec.js
@@ -0,0 +1,41 @@
'use strict';

var Ajv = require('../ajv');
require('../chai').should();


describe('issue #1244: Should skip extendError if "error" option is "full"', function() {
it('should skip extendError if "error" option is "full"', function() {
var ajv = new Ajv({
verbose: true
});
ajv.addKeyword("propertyMustBeTrue", {
// eslint-disable-next-line no-unused-vars
validate: function v(schema, data, _parentSchema, dataPath) {
if (data && !data[schema]) {
v.errors = [{
keyword: "propertyMustBeTrue",
dataPath: dataPath + "." + schema,
data: data[schema]
}];
}
},
errors: "full",
metaSchema: { type: "string" }
});

var schema = {
properties: {
a: { type: "boolean" },
},
propertyMustBeTrue: "a"
};
var data = { a: false };

var validate = ajv.compile(schema);
validate(data) .should.equal(false);
validate.errors.length .should.equal(1);
validate.errors[0].data .should.equal(false);
validate.errors[0].dataPath .should.equal(".a");
});
});

0 comments on commit 11f644e

Please sign in to comment.