Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 712 Bytes

README.md

File metadata and controls

16 lines (12 loc) · 712 Bytes

@testing-library/react behaves differently when dealing with Suspense in React 18 and React 19

In React 18 it was possible to render a component that suspended and assert against both the Suspense fallback and its children once ready, like this:

render(
  <Suspense fallback="fallback">
    <TestComponent />
  </Suspense>
);

expect(screen.getByText("fallback")).toBeInTheDocument();
expect(await screen.findByText("resolved")).toBeInTheDocument();

In React 19 the same test would be stuck on the fallback. Wrapping the render in an awaited act (as suggested by the warning emitted by RTL) makes assertions against the fallback impossible as act returns after Suspense renders its children.