Assert that json does not contain a property
pingvinen opened this issue · 3 comments
pingvinen commented
I have a test in which I would like to assert that the json does not contain the errors
property. I have not found a way to do this yet.
I expected it to be something like expect(response).to.not.have.json('errors')
, but that does not work. It seems to always pass.
Any ideas or pointers?
pingvinen commented
Found a hack, which I would prefer not to keep using.
expect(response).to.have.schema({
type: 'object',
properties: {
errors: {
type: 'justfail'
}
}
});
Which will make the assertion fail when errors
is in the json (as it will have the wrong data type) - and it will pass when errors
is not in the json.
emilbader commented
@pingvinen I have just started out with this so I'm not sure if this might help, but would this approach work?
return expect(response).to.not.comprise.of.json({
errors: {}
});
pingvinen commented
@emilbader That works :)