繁体   English   中英

Chai 期望数组中的对象不包含多个属性

[英]Chai expect objects inside array to not include multiple properties

如何断言数组内的所有对象不包含多个属性。 示例所有这些都不应包括键“电子邮件”和“电话”。

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM