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

Use Jest's fake timers instead of a custom stub #104

Open
mcmire opened this issue Apr 25, 2022 · 1 comment
Open

Use Jest's fake timers instead of a custom stub #104

mcmire opened this issue Apr 25, 2022 · 1 comment

Comments

@mcmire
Copy link
Contributor

mcmire commented Apr 25, 2022

When rewriting the tests in Jest, I used a custom stub for setTimeout / clearTimeout instead of using Jest's fake timers. This turned out to be easier to use at the time because of the way that we use setTimeout in PollingBlockTracker. While writing those tests, I ended up adding some custom events that proved to be useful, one of which is _waitingForNextIteration. Now that this exists, I believe that this is the key to using Jest's fake timers.

@mcmire
Copy link
Contributor Author

mcmire commented Dec 5, 2022

Could also consider flushing promises instead of using _waitingForNextIteration: https://github.com/MetaMask/controllers/pull/1002/files#diff-ead58d4e73060469003c03b4dce6c74d920a2e2357ce7c0e15c3bc8165aad4abR41

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

No branches or pull requests

2 participants