You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{renderHook,waitFor}from"@testing-library/react";import{useState}from"react";beforeAll(()=>{jest.useFakeTimers();});describe("dummy test",()=>{it("I will fail",async()=>{const{ result }=renderHook(()=>{const[data]=useState(false);return{ data };});awaitwaitFor(()=>{// Will obviously fail, but should do so after 5s.expect(result.current.data).toBeTruthy();},{timeout: 5000});});});
What you did:
Running tests with npm run test.
What happened:
The test failed nearly instantly.
However, if I comment the jest.useFakeTimers() line, it works as expected.
I guess it's the same as #1187 . Jest since v27 uses new implementation of fake timers, and as described in #1187, testing library doesn't work with them as of the moment.
@testing-library/react
version: v14.0.0jest
version 29.5.0jsdom
version 29.5.0Relevant code or config:
Here is the test code (designed to fail):
What you did:
Running tests with
npm run test
.What happened:
The test failed nearly instantly.
However, if I comment the
jest.useFakeTimers()
line, it works as expected.Reproduction:
I made a basic repro here.
Problem description:
Using jest fake timers breaks the
waitFor
function.The text was updated successfully, but these errors were encountered: