我怎么写一个间谍,callsFake在西农,类似于茉莉?
茉莉:
spyOn(window, "requestAnimationFrame").and.callFake(() => {});Sinon:
// pseudo code
const requestAnimationFrameSpy = spy().and.callFake(() => {});
global.window.requestAnimationFrame = requestAnimationFrameSpy;发布于 2018-06-07 07:36:29
您可以使用几种不同的方法来完成此操作,或者使用类似于以下内容的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'https://stackoverflow.com/questions/50730728
复制相似问题