How to assert that all objects inside array do not include multiple properties. Example all of them should not include keys "email" and "phone".
const myArray = [ {name: "John Doe", email: "[email protected]", phone: "9xxxxxxxxxx"}, {name: "Jane Doe", email: "[email protected]", phone: "9xxxxxxxxxx"}, {name: "Johny Doe"} ] // this seems to do what I want // but doesn't "something" check if any object passes the test? expect(myArray).to.contain.something.that.does.not.include.any.keys("email", "phone")
Using chai-things.
chai-things
You can filter your array for elements having both keys set:
myArray.filter(a => a.email && a.phone)
and expect the count is 0:
expect(myArray.filter(a => a.email && a.phone)).to.be.an('array').that.is.empty;
2.1m questions
2.1m answers
60 comments
57.0k users