我如何or用chai.should 进行测试?
例如
total.should.equal(4).or.equal(5)
要么
total.should.equal.any(4,5)
什么是正确的语法?我在文档中找不到任何内容
nya*_*sha 25
查看Chai expect/should文档,有几种方法可以进行此测试.
请注意,您可以使用"和"进行链接,但显然不是"或" - 希望他们具有此功能.
.satisfy(方法)
@param{ Function }matcher
@param{ String }message_optional_
Asserts that the target passes a given truth test.
例:
expect(1).to.satisfy(function(num) { return num > 0; });
在您的情况下,测试"或"条件:
yourVariable.should.satisfy(function (num) {
    if ((num === 4) || (num === 5)) {
        return true;
    } else {
        return false;
    }
});
.within(开始,结束)
@param{ Number }startlowerbound inclusive
@param{ Number }finishupperbound inclusive
@param{ String }message_optional_
Asserts that the target is within a range.
例:
expect(7).to.be.within(5,10);
Esq*_*uth 14
断言目标是给定数组列表的成员。但是,通常最好断言目标等于其预期值。
expect(1).to.be.oneOf([1, 2, 3]);
expect(1).to.not.be.oneOf([2, 3, 4]);
https://www.chaijs.com/api/bdd/#method_oneof
| 归档时间: | 
 | 
| 查看次数: | 10753 次 | 
| 最近记录: |