如何使Chai自定义断言失败?

时间:2019-05-14 22:12:59

标签: javascript node.js mocha chai

此最小示例自定义chai断言应该失败。它不是。使失败的原因是什么?

const chai = require('chai');

chai.Assertion.addMethod('test1', function() {
    this.assert(
        false,
        "Failed",
        "Failed",
        "foo",
        "bar"
    );
});

chai.expect({}).to.be.test1;

1 个答案:

答案 0 :(得分:0)

test1必须被调用。如: chai.expect({}).to.be.test1();