Javascript 在Jasmine中使用createSpy测试模块内部设置间隔

Javascript 在Jasmine中使用createSpy测试模块内部设置间隔,javascript,node.js,unit-testing,jasmine,Javascript,Node.js,Unit Testing,Jasmine,在nodejs类中,我有一个名为_timerEvent的内部函数,它将从setInterval调用 这些调用有两个方法,第一个方法调用startInterval和stopInterval this._timerForInterval = setInterval(this._timerEvent, this._interval * 1000); 呼叫停止间隔呼叫 clearInterval(this._timerForInterval); 现在我想用jasmine测试一下是否调用了这个。\u

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

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

this._timerForInterval = setInterval(this._timerEvent, this._interval * 1000);
呼叫停止间隔呼叫

clearInterval(this._timerForInterval);
现在我想用jasmine测试一下是否调用了
这个。\u 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();
我得到了错误:
“应该是间谍,但得到了null”

我尝试了几种方法,但如果使用jasmine.clock,我想我没有得到这个概念


有人能告诉我正确的方法吗?

请在每次之前在
中尝试
createSpy
install()
。和
jasmine