I have been able to get the error messages produced from tv4.validateMultiple to show in the Test Results, but I cannot figure out how to set them to show fail status.
var jsonData = JSON.parse(responseBody);
var schema = {...contains multiple error}
var results = tv4.validateMultiple(jsonData, schema);
if(results.valid){
pm.test('Response has valid schema') = true;
} else {
for (var i = 0; i < results.errors.length; i++) {
pm.test("Contract: JSON Response has invalid schema in path [" + results.errors[i].dataPath + " | " + results.errors[i]);
}
}
Multiple messages are logged in the Test Results tab, but have a status of pass. With the 'old style' Postman tests[], you can set it = false. But that can't be used in a for loop because the test will end on first fail. pm.test will continue but the status is pass.
I tried placing the pm.test('Schema is valid', function() {pm.expect...} in a for loop but get the message "Don't make functions in a loop" message. So I tried pulling the function part outside, which didn't work either.
I've also tried Ajv and setting allErrors: true.
All I want to do is validate an entire response and report all failures in the Test Tab and xtrareports.