From 8aee286cc8c63a9d2794a8a2f4574f6a44d0917c Mon Sep 17 00:00:00 2001 From: Pradip Date: Tue, 23 Mar 2021 09:59:26 +0100 Subject: [PATCH] Testing Recipes - Timers: call useFakeTimers/userRealTimers before/after each test (#3591) --- content/docs/testing-recipes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/docs/testing-recipes.md b/content/docs/testing-recipes.md index 875522591..1fa4a6969 100644 --- a/content/docs/testing-recipes.md +++ b/content/docs/testing-recipes.md @@ -465,13 +465,12 @@ import { act } from "react-dom/test-utils"; import Card from "./card"; -jest.useFakeTimers(); - let container = null; beforeEach(() => { // setup a DOM element as a render target container = document.createElement("div"); document.body.appendChild(container); + jest.useFakeTimers(); }); afterEach(() => { @@ -479,6 +478,7 @@ afterEach(() => { unmountComponentAtNode(container); container.remove(); container = null; + jest.useRealTimers(); }); it("should select null after timing out", () => {