Mocha,Chai:断言Object包含在一个对象数组中 [英] Mocha, Chai: Assert that Object is included in an Array of Objects

查看:209
本文介绍了Mocha,Chai:断言Object包含在一个对象数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chai有一种很好的方法断言一个数组是否包含某个元素

Chai has a nice way to assert if an Array includes a certain element

expect([1,2,3]).to.include(2);

给定一个对象数组,我想要的是类似的东西:

What I would like is something similar, given an Array of Objects:

expect([{a:1},{b:2}]).to.include({b:2});

这可能吗?

推荐答案

查看 Chai Things插件,它可以满足您的需求:

Take a look at the Chai Things plugin, that does what you want:

[{a:1},{b:2}].should.include.something.that.deep.equals({b:2})

这篇关于Mocha,Chai:断言Object包含在一个对象数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆