Chai 期望数组中的对象不包含多个属性
Chai expect objects inside array to not include multiple properties
如何断言数组中的所有对象都不包含多个属性。
例如,所有这些都不应该包含键“email”和“phone”。
const myArray = [
{name: "John Doe", email: "john@gmail.com", phone: "9xxxxxxxxxx"},
{name: "Jane Doe", email: "jane@gmail.com", 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")
使用 chai-things
.
您可以过滤数组以查找同时设置了两个键的元素:
myArray.filter(a => a.email && a.phone)
并期望计数为 0:
expect(myArray.filter(a => a.email && a.phone)).to.be.an('array').that.is.empty;
如何断言数组中的所有对象都不包含多个属性。 例如,所有这些都不应该包含键“email”和“phone”。
const myArray = [
{name: "John Doe", email: "john@gmail.com", phone: "9xxxxxxxxxx"},
{name: "Jane Doe", email: "jane@gmail.com", 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")
使用 chai-things
.
您可以过滤数组以查找同时设置了两个键的元素:
myArray.filter(a => a.email && a.phone)
并期望计数为 0:
expect(myArray.filter(a => a.email && a.phone)).to.be.an('array').that.is.empty;