testing-library / testing-library/dom-testing-library
findBy* no longer waiting when used with jest fake timers
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/domversion: 8.0.0- Testing Framework and version:
@testing-library/reactv12 - DOM Environment: jest 27
Relevant code or config:
"jest": {
"testEnvironment": "jsdom",
"setupFilesAfterEnv": ["<rootDir>/jest-setup.js"]
}
// jest-setup.js
import '@testing-library/jest-dom'
What you did:
I was trying to use fake timers and findBy*
What happened:
findBy* doesn't wait when using fake timers as it used to.
Reproduction:
Created a repo with two branches, one using v11 of RTL and another one for v12.
v11 branch works fine (dom v7.31.2)
v12 branch is experiencing issues (dom v8)
https://github.com/deini/rtl-find/tree/v11
https://github.com/deini/rtl-find/tree/v12
Problem description:
When doing something like:
jest.useFakeTimers();
render(<Button />)
await screen.findByRole('dialog', {}, { timeout: 5000 })
I would expect it to wait for 5 seconds (unless I'm totally wrong 😅), however, seems like fake timers is now messing up with findBy* and it doesn't wait anymore. This happens both in jest 26 and 27 with both legacy and modern fake timers.
Suggested solution:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked v11 and v12 reproduction branches and the screen.findByRole call using fake timers; compare the behavior across the DOM Testing Library versions. Review jest-setup.js and the async waiting entry point, then add a regression test covering Jest fake timers and confirm that findBy* waits according to its timeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100