3
我正在使用Mocha和sinon间谍函数调用。该函数被正确调用,但间谍没有跟踪它。Sinon间谍函数调用但未跟踪
这里是我的测试
export default (() => {
function test1(){
console.log('called second func');
return 5;
}
function callThis(){
console.log('called first func');
test1();
}
return {
test1,
callThis
};
})();
模块,这里是测试
import Common from './common';
describe('spy test',() => {
var setSpy = sinon.spy(Common, 'test1');
Common.callThis();
var result = setSpy.called;
it(`does the test`,() => {
expect(result).to.equal(true);
});
});
我基本上调用第一功能,但要检查的第二个函数被调用的结果。控制台日志告诉我这是发生,但间谍返回false,并没有注意到它正在监视的事情。我错过了什么吗?