开发者

How to test for user-specified time in setTimeout

Right now I have a jQuery plugin that adds some extra customization (around how to handle the return data in certain contexts) and polling a server for information and changes. One of the required features is to allow the user set the polling interval. setTimeout (paired with recursion) is the function that is used for creating the constant poll; this is also a requirement.

This is where I am stumped: along with the required functionality noted above, I also have to test if the user-specified value was actually used in the setTimeou开发者_高级运维t. How would I go about doing this from a QUnit perspective?

I have already pondered straight timing the function with Date.getTime(), but the way things are currently set up this isn't an option.


Consider refactoring the code in a way that let's you override the method starting the timeout within your test, allowing you to verify that the correct value is passed, without actually starting the timeout.

If you need to actually call setTimeout, consider using sinon.js to mock setTimeout itself and control what it does instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜