Mocha Chai - Test multiple properties of object

If you're exclusively utilising Chai (in Postman, for example), the following string of functions will successfully aid you:

response.body.to.include.all.keys("active", "mobileNumber");

The full list of API's (including an example of the above) can be found here.


Found how to achieve it using mocha chai-should,

Function name is .should.have.keys() Just pass the properties to this function and it will check they should be present in the object you are testing.

bellow is the code

response.body.should.have.keys('active', 'mobileNumber', 'countryCode', 'username', 'email', 'id', 'organisationId', 'createdAt', 'updatedAt', 'location');

Tags:

Mocha.Js

Chai