Description
@testing-library/react
version: 16.2.0- Testing Framework and version: Vitest v3.0.9
- DOM Environment: JSDOM v26
Relevant code or config:
The assertion in the following snippets fails in React 19, but succeeds in React 18:
test("renders in strict mode when using a wrapper", async () => {
let mounted = 0;
function Component() {
React.useEffect(() => {
mounted += 1;
});
return null;
}
render(<Component />, { wrapper: Wrapper });
expect(mounted).toEqual(2);
});
● › renders in strict mode when using a wrapper
expect(received).toEqual(expected) // deep equality
Expected: 2
Received: 1
18 | render(<Component />, { wrapper: Wrapper });
> 20 | expect(mounted).toEqual(2);
| ^
21 | });
What you did:
Rendered StrictMode
in Wrapper
component that is passed do the wrapper
property of the options object in the render
function from React Testing Library.
What happened:
Expected Strict Mode to be enabled, but it wasn't. This can be seen because in Strict Mode in React 18 and 19 useEffect
should be run twice, but in this case it was only run once.
This issue only happens in React 19. In React 18 it works as expected.
Reproduction:
React 19 - tests fail
React 18 - tests pass
Problem description:
In React 19, when rendering React.StrictMode
in a component provided to wrapper
, Strict Mode isn't enabled.
In React 18, however, Strict Mode is enabled.
Suggested solution:
In React 19, rendering React.StrictMode
in a component provided to wrapper
should enable Strict Mode.