我是新来的茉莉花和间谍的事情,希望你能指出正确的方向。正在使用spyOn()而没有可能的方法吗?
我有一个我想与单元测试覆盖的事件侦听器:
var nextTurn = function() {
continueButton.addEventListener("click", displayComputerSelection)
};
nextTurn();
的总体思路是,以窥探“displayComputerSelection”功能。
it ("should call fn displayComputerSelection on continueButton click", function(){ spyOn(displayComputerSelection); continueButton.click(); expect(displayComputerSelection).toHaveBeenCalled();
由于间谍的基本结构是spyOn(<object>, <methodName>)
我得到回应No method name supplied
。 我试过试用jasmine.createSpy,但无法使其工作。 我将如何替换预期的方法?
非常感谢! 'displayComputerSelection'是一个全局变量,所以我发现我只需要使用'window'作为一个对象。 所以它这样工作: 'spyOn(window,“displayComputerSelection”);'' –