Skip to content

Reproduction repo for @testing-library/react that shows different behaviors when testing Suspense in React 19 vs React 19

Notifications You must be signed in to change notification settings

aheadintranet/react-18-19-suspense-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

@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.

About

Reproduction repo for @testing-library/react that shows different behaviors when testing Suspense in React 19 vs React 19

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published