Skip to content

Commit

Permalink
Add test for empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Barosan committed Apr 4, 2019
1 parent 0f444a2 commit a11b433
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dist/ZSchema-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7231,7 +7231,8 @@ var FormatValidators = require("./FormatValidators"),
var shouldSkipValidate = function (options, errors) {
return options &&
Array.isArray(options.includeErrors) &&
(options.includeErrors.length === 0 || !errors.some(function (err) { return options.includeErrors.includes(err);}));
options.includeErrors.length > 0 &&
!errors.some(function (err) { return options.includeErrors.includes(err);});
};

var JsonValidators = {
Expand Down
3 changes: 2 additions & 1 deletion src/JsonValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var FormatValidators = require("./FormatValidators"),
var shouldSkipValidate = function (options, errors) {
return options &&
Array.isArray(options.includeErrors) &&
(options.includeErrors.length === 0 || !errors.some(function (err) { return options.includeErrors.includes(err);}));
options.includeErrors.length > 0 &&
!errors.some(function (err) { return options.includeErrors.includes(err);});
};

var JsonValidators = {
Expand Down
24 changes: 23 additions & 1 deletion test/ZSchemaTestSuite/IncludeErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,33 @@ module.exports = {
hello: "world",
extra: "extra"
},
description: "should fail validation for all errors when empty array is provided.",
description: "should fail validation for all errors when no `includeErrors` array is provided.",
valid: false,
after: function(errs) {
expect(errs.length).toBe(2);
}
},
{
schema: {
"type": "object",
"properties": {
"hello": {
"type": "number"
}
}
},
data: {
hello: "world",
extra: "extra"
},
validateOptions: {
includeErrors: []
},
description: "should fail validation for all errors when empty array is provided.",
valid: false,
after: function(errs) {
expect(errs.length).toBe(2);
}
}
]
};

0 comments on commit a11b433

Please sign in to comment.