-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed as not planned
Labels
Description
@testing-library/react
version: 16.0.0- Testing Framework and version: [email protected]
- DOM Environment: [email protected]
Relevant code or config:
import { renderHook, waitFor } from "@testing-library/react";
import { Suspense, use } from "react";
test("does not timeout", async () => {
const initialPromise = Promise.resolve("test");
console.time("executing hook");
console.time("asserting");
const { result } = renderHook(
() => {
console.timeLog("executing hook");
const result = use(initialPromise);
console.log("got result in render", result);
return result;
},
{
wrapper: ({ children }) => {
return <Suspense fallback={<div>loading</div>}>{children}</Suspense>;
},
}
);
await waitFor(() => {
console.timeLog("asserting");
console.log(result);
expect(result.current).toEqual("test");
});
}); //, 300
/** adding the 300ms timeout above would make this test fail */
What you did:
We found this in the Apollo Client tests, where one file went from executing in 10s with React 18 to 80s in React 19.
What happened:
The test takes 300ms longer than expected (if there were multiple suspenseful renders, it would take 600,900 etc.):
% npm test main
> [email protected] test
> jest
console.time
executing hook: 5 ms
at wrapper.children.children (src/slow.test.tsx:10:15)
console.time
asserting: 24 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
executing hook: 29 ms
at wrapper.children.children (src/slow.test.tsx:10:15)
console.log
got result in render test
at wrapper.children.children (src/slow.test.tsx:12:15)
console.time
asserting: 75 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
asserting: 127 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
asserting: 179 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
asserting: 231 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
asserting: 284 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
asserting: 326 ms
at src/slow.test.tsx:23:13
console.log
{ current: null }
at src/slow.test.tsx:24:13
console.time
asserting: 337 ms
at src/slow.test.tsx:23:13
console.log
{ current: 'test' }
at src/slow.test.tsx:24:13
PASS src/slow.test.tsx
✓ does not timeout (342 ms)
Reproduction:
https://github.com/phryneas/react-19-reproduction-slow-tests
Problem description:
I can seem to only reproduce this with renderHook
so far, I had no success reproducing it with render
itself (but I might be missing something).
alessbell