gpt4 book ai didi

chai - 如何在 chai 中做一个 "or"应该

转载 作者:行者123 更新时间:2023-12-03 10:13:36 35 4
gpt4 key购买 nike

我该如何做 or使用 chai.should 进行测试?
例如就像是

total.should.equal(4).or.equal(5)
或者
total.should.equal.any(4,5)
什么是正确的语法?我在文档中找不到任何内容。

最佳答案

查看 Chai expect / should documentation ,有几种方法可以进行此测试。

请注意,您可以使用“和”进行链接,但显然不能使用“或”——希望他们有这个功能。

  • 检查对象是否通过真值测试:

  • .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);

    关于chai - 如何在 chai 中做一个 "or"应该,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32387293/

    35 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com