在Jasmine中使用createSpy来testing模块内部的setInterval

在一个nodejs类中,我有一个called _timerEvent的内部函数,它将从setInterval中调用。

调用有两个方法,第一个方法调用的startInterval和stopInterval

 this._timerForInterval = setInterval(this._timerEvent, this._interval * 1000); 

调用stopIntervall调用

 clearInterval(this._timerForInterval); 

现在我想用茉莉花testing如果this._timerEvent被调用:

 var spyTimerEvent = null; controller._timerEvent = jasmine.createSpy('spyTimerEvent'); jasmine.clock().install(); controller.setInterval(60); controller.startInterval(); expect(spyTimerEvent).not.toHaveBeenCalled(); jasmine.Clock().tick(61); expect(spyTimerEvent).toHaveBeenCalled(); jasmine.clock().uninstall(); 

我得到的错误: "Expected a spy, but got null"

我尝试了几种方法,但我认为如果使用jasmine.clock,我没有这个概念。

任何人都可以用正确的方式暗示我吗?