Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React.StrictMode not working when child of wrapper in React 19 #1388

Closed
@bernardobelchior

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:

function Wrapper({ children }) {
 return <React.StrictMode>{children}</React.StrictMode>;
}
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /