Skip to content

Commit

Permalink
Remove warning in NetworkController unit tests (#1300)
Browse files Browse the repository at this point in the history
In the NetworkController unit tests we use `setTimeout` to wait for
events to occur. We also use `clearTimeout` in the same context to stop
waiting if need be. Because we use fake timers in these tests we need
the original versions of these functions and not the fake versions. We
already capture the original version of `setTimeout` up front, but we
don't do the same for `clearTimeout`, and that leads to a warning being
printed when we use it. This commit captures `clearTimeout` up front as
well to prevent this warning.

Co-authored-by: Mark Stacey <[email protected]>
  • Loading branch information
2 people authored and MajorLift committed Oct 11, 2023
1 parent ef6d0bd commit 02b2325
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/network-controller/tests/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ jest.mock('uuid', () => {
};
});

// Store this up front so it doesn't get lost when it is stubbed
// Store these up front so we can use them even when faking timers
const originalSetTimeout = global.setTimeout;
const originalClearTimeout = global.clearTimeout;

const createNetworkClientMock = jest.mocked(createNetworkClient);

Expand Down Expand Up @@ -7510,7 +7511,7 @@ async function waitForPublishedEvents<E extends NetworkControllerEvents>(
*/
function stopTimer() {
if (timer) {
clearTimeout(timer);
originalClearTimeout(timer);
}
}

Expand Down

0 comments on commit 02b2325

Please sign in to comment.