joshua
(Joshua Dickerson)
October 22, 2019, 4:39pm
1
I have a test:
pm.test('schema valid', () => {
const validation = tv4.validate(response, schema);
if (!validation) {
console.error(tv4.error)
}
pm.expect(validation || tv4.error.message).to.be.true;
})
I get a failure: schema valid | AssertionError: expected 'Invalid type: null (expected string)' to be true
There are 316 "null"s when I search for the result. How can I make this test give me a better message so I can find where it is failing?
The response is a JSON object with one property “products”. That property is an array of objects.
Hey @joshua ,
I would suggest switching over to using the Ajv module instead, it might have the solution you’re looking for, in terms of exposing more valuable error messages.
There have been a number of threads on the forums that have referenced how to do this:
Hey @Coxjeffrey ,
I would recommend using Ajv over tv4, this also comes as part of the Postman app.
You can use this example to check your response against the schema:
var Ajv = require('ajv'),
ajv = new Ajv({ logger: console, allErrors: true }),
schema = {
"type":"object",
"required":[
"Id",
"Progress",
"Status",
"Info",
"Created",
"Ended",
"Operation",
"Requested"
],
"properties":{
"Id":{
"$id":"#/properties/I…