javascript - Expect deep property to have any of multiple values - Stack Overflow

In Chai assertion library, we can assert a deep property to exist and have a value:expect(obj).to.have.

In Chai assertion library, we can assert a deep property to exist and have a value:

expect(obj).to.have.deep.property("field1.field2", 1);

But, what if we need to assert this property to have one of multiple values? In this case, the test should pass if obj has a field1.field2 property that has 0 or 1 or 2 value.


FYI, I need this to check that a ESLint plugin ships with a remended rules configuration that has a "warning level" configured for every rule. Warning level can be of 0, 1 or 2 values.

In Chai assertion library, we can assert a deep property to exist and have a value:

expect(obj).to.have.deep.property("field1.field2", 1);

But, what if we need to assert this property to have one of multiple values? In this case, the test should pass if obj has a field1.field2 property that has 0 or 1 or 2 value.


FYI, I need this to check that a ESLint plugin ships with a remended rules configuration that has a "warning level" configured for every rule. Warning level can be of 0, 1 or 2 values.

Share edited Jun 29, 2016 at 17:57 alecxe asked Jun 29, 2016 at 17:50 alecxealecxe 475k127 gold badges1.1k silver badges1.2k bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can use .oneOf():

expect(obj).to.have.deep.property('field1.field2').that.is.oneOf([ 0, 1, 2 ])

Or .within():

expect(obj).to.have.deep.property('field1.field2').that.is.within(0, 2)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744862593a4597791.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信