最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论