我正在使用带有假计时器的sinon
,我想检查是否使用特定的超时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);