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

Allow injecting a custom setTimeout? #22

Closed
JoshuaKGoldberg opened this issue Jun 21, 2018 · 2 comments
Closed

Allow injecting a custom setTimeout? #22

JoshuaKGoldberg opened this issue Jun 21, 2018 · 2 comments

Comments

@JoshuaKGoldberg
Copy link

Hardcoding this to always use the global setTimeout is problematic. In most unit testing frameworks, there's no way to programmatically skip forward to the execution time - we'd have to also setTimeout in the tests.

Proposal: allow debounce method to take in an object containing the settings, as it's starting to accept quite a few. What if we want to specify wait and setTimeout but not immediate?

@seiyab
Copy link

seiyab commented Nov 6, 2021

FYI: jest has Timer Mocks

@sindresorhus
Copy link
Owner

I'm going to pass on this. Timer mocking is the defacto way to handle this. You generally don't use debounce directly in your tests, so you would then have to pass these through from your own functions too. And every package you use that use a timer internally would have to support passing in the timer globals for this to work.

@sindresorhus sindresorhus closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2023
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

Successfully merging a pull request may close this issue.

3 participants