javascript - How to check if clearTimeout was called with sinon.useFakeTimers? - Stack Overflow

I'm using sinon with fake timers and I want to check if clearTimeout was called with a specific ti

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?

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?
Share Improve this question asked Dec 28, 2017 at 17:00 MottiMotti 115k56 gold badges194 silver badges274 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744774073a4592938.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信