Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Way to check that there are zero waiting timers #213

Closed
thejohnfreeman opened this issue Oct 4, 2018 · 6 comments
Closed

[feat] Way to check that there are zero waiting timers #213

thejohnfreeman opened this issue Oct 4, 2018 · 6 comments

Comments

@thejohnfreeman
Copy link
Contributor

It'd be nice to have a method that can tell me if there are any waiting timers, so I can assert in tests that every timer has run or been cleaned up.

Reading the code, I see that clocks have a timers property which is an object mapping timer IDs to timers. I could check that that object has zero own properties, but it is not a documented part of the public API, so I'm at risk of breaking changes.

Another option would have runAll return the number of timers it ran, so that I could assert at the end of my tests that number is zero, but it is returning clock.now in the current version. That does not appear to be a documented part of the API, but changing it risks breaking users mistakenly depending on it.

What do you think?

@SimenB
Copy link
Member

SimenB commented Oct 4, 2018

Dupe of #163.

We need this in Jest as well, FWIW.

@fatso83
Copy link
Contributor

fatso83 commented Oct 5, 2018

I think we would love a PR for such a feature 😉 Check out #163 for some background on what we need.

@thejohnfreeman
Copy link
Contributor Author

I'll work on it this weekend. Just some docs and test(s) on the return value of .uninstall?

@SimenB
Copy link
Member

SimenB commented Oct 5, 2018

We shouldn't have to uninstall to get the count. I might want to check e.g. remaining timers per run of my function or something

@benjamingr
Copy link
Member

We shouldn't have to uninstall to get the count. I might want to check e.g. remaining timers per run of my function or something

Did anyone actually ever ask for that for a real use case? Not saying that it's not important - only that I haven't seen a request.

@SimenB
Copy link
Member

SimenB commented Oct 6, 2018

Facebook has a test for debouncing or something like that, which checks how many timers are scheduled after calling a function. Not sure if the uninstall would be enough in that case, actually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants