如何编写一个在Sinon中调用Fake的间谍,类似于Jasmine?
茉莉花:
spyOn(window, "requestAnimationFrame").and.callFake(() => {});
兴农:
// pseudo code
const requestAnimationFrameSpy = spy().and.callFake(() => {});
global.window.requestAnimationFrame = requestAnimationFrameSpy;
答案 0 :(得分:2)
您可以通过几种不同的方式执行此操作,sinon fakes类似于:
const requestAnimationFrameSpy = sinon.fake().returns({value:'some value'});
global.window.requestAnimationFrame = requestAnimationFrameSpy();
您也可以使用sinon stubs:
执行此操作//from sinon website
var myObj = {};
myObj.prop = function propFn() {
return 'foo';
};
sinon.stub(myObj, 'prop').callsFake(function fakeFn() {
return 'bar';
});
myObj.prop(); // 'bar'