testing-library / testing-library/user-event
`userEvent.click` doesn't ignore hidden elements as the documentation says
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Description
Reproduction example
https://codesandbox.io/s/user-event-invisible-button-xpw2kf
Prerequisites
- Render an invisble button:
<button onClick={() => setClicked(true)} style={{visibility: 'hidden'}}>
Click me!
</button>
- Select the button.
- Click the button using the
clickfunction ofuserEvent.
Expected behavior
The click function shouldn't work on invisible HTML elements. Maybe an error should be thrown in that case.
Actual behavior
Even though the documentation says
It adds visibility and interactability checks along the way and manipulates the DOM just like a user interaction in the browser would. It factors in that the browser e.g. wouldn't let a user click a hidden element or type in a disabled text box.
the click function still works on the invisible button.
User-event version
14.4.3
Environment
No response
Additional context
No response
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 CodeSandbox reproduction and the userEvent click implementation for version 14.4.3. Verify how visibility and interactability checks handle the button styled with visibility:hidden, then confirm that clicking it no longer succeeds as described in the issue and that the documentation behavior is consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100