小编gia*_*gnn的帖子

sinon间谍独立功能

当我在对象内部的函数上使用Sinon时,它可以工作:

function myFunc() {
    console.log('hello');
}
var myObj = { myFunc: myFunc };
var spy = sinon.stub(myFunc);
myObj.myFunc();
expect(spy.called).to.be.true(); 
Run Code Online (Sandbox Code Playgroud)

但是,我不知道为什么当我在独立函数上使用Sinon时如下:

function myFunc() {
    console.log('hello');
}
var spy = sinon.stub(myFunc);
myFunc();
expect(spy.called).to.be.true(); 
Run Code Online (Sandbox Code Playgroud)

断言失败了.

sinon

17
推荐指数
2
解决办法
9846
查看次数

标签 统计

sinon ×1