我正在使用sinon
和fake timers,我想检查是否使用特定的timeout-id调用clearTimeout
。
var clock = sinon.useFakeTimers();
functionUnderTest();
// How can I know if functionUnderTest cleared a specific timeout?
clock
对象有sinon的定时器相关函数,你可以spy
他们然后断言他们被调用
var clock = sinon.useFakeTimers();
sinon.spy(clock, "clearTimeout");
functionUnderTest();
sinon.assert.calledWith(clock.clearTimeout, 42);