-
-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Phoenix He
committed
Jul 13, 2020
1 parent
ed06ad9
commit 11f644e
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
spec/issues/1244_custom_validate_should_skip_extenderrors.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}); |