I'm using sinon
with fake timers and I want to check if clearTimeout
was called with a specific timeout-id.
var clock = sinon.useFakeTimers();
functionUnderTest();
// How can I know if functionUnderTest cleared a specific timeout?
The clock
object has sinon's timer related functions, you can spy
them and then assert that they were called
var clock = sinon.useFakeTimers();
sinon.spy(clock, "clearTimeout");
functionUnderTest();
sinon.assert.calledWith(clock.clearTimeout, 42);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With