dareid / chakram

REST API test framework. BDD and exploits promises
http://dareid.github.io/chakram/
MIT License
908 stars 99 forks source link

Assert that json does not contain a property #119

Closed pingvinen closed 6 years ago

pingvinen commented 6 years ago

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 6 years ago

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 6 years ago

@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 6 years ago

@emilbader That works :)