Skip to content

Commit e2c67ae

Browse files
committed
add multiple option
1 parent 80473ea commit e2c67ae

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ chai.tv4.banUnknown = true;
156156

157157
Passed to the internal `tv4` validate call makes validation fail on unknown schema properties. Use this to make sure your schema do not contain undesirable data.
158158

159+
**Validate multiple errors**
160+
161+
````js
162+
chai.tv4.multiple = true;
163+
````
164+
165+
Call `tv4.validateMultiple` for validation instead of `tv4.validateResult`. Use this if you want see all validation errors.
166+
167+
159168
### Remote references
160169

161170
Due to the synchronous nature of assertions there will be no support for dynamically loading remote references during validation.

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
chai.tv4 = tv4Module.freshApi();
3939
chai.tv4.cyclicCheck = false;
4040
chai.tv4.banUnknown = false;
41+
chai.tv4.multiple = false;
4142

4243
function forEachI(arr, func, scope) {
43-
for (var i = arr.length, ii = arr.length; i < ii; i++) {
44+
for (var i = 0, ii = arr.length; i < ii; i++) {
4445
func.call(scope, arr[i], i, arr);
4546
}
4647
}
@@ -131,7 +132,12 @@
131132
assert.ok(schema, 'schema');
132133

133134
// single result
134-
var result = chai.tv4.validateResult(obj, schema, chai.tv4.cyclicCheck, chai.tv4.banUnknown);
135+
var result = null;
136+
if(chai.tv4.multiple) {
137+
result = chai.tv4.validateMultiple(obj, schema, chai.tv4.cyclicCheck, chai.tv4.banUnknown);
138+
} else {
139+
result = chai.tv4.validateResult(obj, schema, chai.tv4.cyclicCheck, chai.tv4.banUnknown);
140+
}
135141
// assertion fails on missing schemas
136142
var pass = result.valid && (result.missing.length === 0);
137143

0 commit comments

Comments
 (0)