MetaMask / eth-block-tracker

A JS module for keeping track of the latest Ethereum block by polling an ethereum provider
MIT License
132 stars 81 forks source link

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

Open mcmire opened 2 years ago

mcmire commented 2 years ago

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 commented 1 year ago

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