mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-22 20:01:57 +00:00
Testing Recipes - Timers: call useFakeTimers/userRealTimers before/after each test (#3591)
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user