MetaMask / MetaMask/core

[eth-block-tracker] Use Jest's fake timers instead of a custom stub

Open
#6,868 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

team-wallet-framework wf-test-quality-improvement
Dominant language
TypeScript
Stars
413
Forks
308
Avg merge
1d 4h
Merged PRs (30d)
253

Description

When [rewriting the tests in Jest](https://github.com/MetaMask/eth-block-tracker/pull/103), 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Jest test rewrite in pull request #103 and the PollingBlockTracker tests, then trace how the custom setTimeout/clearTimeout stub and the _waitingForNextIteration event are used. Done means the custom timer stub is replaced with Jest fake timers while the existing tests continue to pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.