From 9f899d52aff2a1356ceda00ae5232987d4415623 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 11 May 2020 16:05:50 +0200 Subject: [PATCH 1/2] mention "modern" fake timers implementation It's currently difficult to find out, that it's even possible to try this new implementation. I've accidentally met it in the release notes. --- docs/TimerMocks.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/TimerMocks.md b/docs/TimerMocks.md index 68c449847813..0bcc75956488 100644 --- a/docs/TimerMocks.md +++ b/docs/TimerMocks.md @@ -37,6 +37,8 @@ test('waits 1 second before ending the game', () => { Here we enable fake timers by calling `jest.useFakeTimers();`. This mocks out setTimeout and other timer functions with mock functions. If running multiple tests inside of one file or describe block, `jest.useFakeTimers();` can be called before each test manually or with a setup function such as `beforeEach`. Not doing so will result in the internal usage counter not being reset. +Currently, two implementations of the fake timers are present - `modern` and `legacy`, where `legacy` is still the default one. You can read how to enable `modern` implementation [here](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers). + ## Run All Timers Another test we might want to write for this module is one that asserts that the callback is called after 1 second. To do this, we're going to use Jest's timer control APIs to fast-forward time right in the middle of the test: From fc640bd388dd22710cfc7152e1d66bb9865b968a Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 11 May 2020 16:28:56 +0200 Subject: [PATCH 2/2] Update docs/TimerMocks.md Co-authored-by: Simen Bekkhus --- docs/TimerMocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/TimerMocks.md b/docs/TimerMocks.md index 0bcc75956488..ef40cf373285 100644 --- a/docs/TimerMocks.md +++ b/docs/TimerMocks.md @@ -37,7 +37,7 @@ test('waits 1 second before ending the game', () => { Here we enable fake timers by calling `jest.useFakeTimers();`. This mocks out setTimeout and other timer functions with mock functions. If running multiple tests inside of one file or describe block, `jest.useFakeTimers();` can be called before each test manually or with a setup function such as `beforeEach`. Not doing so will result in the internal usage counter not being reset. -Currently, two implementations of the fake timers are present - `modern` and `legacy`, where `legacy` is still the default one. You can read how to enable `modern` implementation [here](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers). +Currently, two implementations of the fake timers are present - `modern` and `legacy`, where `legacy` is still the default one. You can read how to enable `modern` implementation [here](/blog/2020/05/05/jest-26#new-fake-timers). ## Run All Timers