当我在对象内部的函数上使用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 ×1