Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if clearTimeout was called with sinon.useFakeTimers?

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?
like image 221
Motti Avatar asked Dec 23 '22 11:12

Motti


1 Answers

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);
like image 199
Motti Avatar answered Dec 29 '22 00:12

Motti