gpt4 book ai didi

javascript - to.have.been.calledWith is not a function 错误 in chai#3.5.0

转载 作者:搜寻专家 更新时间:2023-11-01 05:28:24 32 4
gpt4 key购买 nike

我已经在我的项目中更新了 chai 的版本,在更新到 3.5.0 之后,一些测试失败了。我发现我无法测试我监视的函数的参数。

我创建了一个 fiddle 来用这里的示例方法重现我的问题 - JSFiddle

describe('Mocha + Chai JsFiddle', function() {

it('should test arg', function() {
var spy = sinon.spy(test, 'testFun');

test.testFun(5);

expect(spy).to.have.been.called.with(5);
});
});

谁能建议我们如何在较新版本的 chai.js 中测试参数?

最佳答案

当您使用 Sinon 时,您可以使用 Sinon spy 方法并使用 Chai 检查结果:

expect(spy.calledWith(5)).to.equal(true);

或者您可以使用 sinon-chai这会让你做:

expect(spy).to.have.been.calledWith(5);

See a JSFiddle of the first example

关于javascript - to.have.been.calledWith is not a function 错误 in chai#3.5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43995861/

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