Let's say I have an array
let array_of_string = ['John','Jack','Smith','Ryan'];
How can I assert that these keys are included in JSON array of objects where the JSON is something like this
[ {
"person_name": "Jake",
"person_id": '1234',
"employee_type": "Regular"
}, {
"person_name": "Adam",
"person_id": '1245',
"employee_type": "Contractor"
}, {
"person_name": "John",
"person_id": '2342',
"employee_type": "Regular"
}, {
"person_name": "Smith",
"person_id": '3456',
"employee_type": "Contractor"
}, {
"person_name": "Ryan",
"person_id": '0123',
"employee_type": "Regular"
} ]
I am using Chai
to have the assertions. Using include
and deep.Equal
doesn't seem to work.
The JSON Array is response of an API. So currently I tried this
it('checks if the elements are in API response', () => {
return response.then(function(resp){
expect(resp).to.be.an('array').that.includes(array_of_string )
})
})