Description
@testing-library/react
version: 14.0.0- Testing Framework and version: Jest 29.4.3
- DOM Environment: jsdom 29.4.3
Relevant code or config:
const buttons = await waitFor(
screen.getAllByRole("button", { hidden: true })
);
logRoles(buttons)
What you did:
I was trying to logRoles
for a DOM tree with hidden elements. Failed to see the elements show in the roles list.
What happened:
Logging roles for hidden elements produces an empty log.
Reproduction:
- Get all elements of a DOM tree including hidden ones. Make sure you have hidden ones.
- Log using
logRoles
- See that some log entries are empty compared to what you see when you
screen.debug
Problem description:
If you log an element you found using { hidden: true }
, logRoles
will not print it. Similarly won't print hidden elements in a DOM tree you pass in. This is the opposite of what I would expect from this tool. I want to know why something may be failing to query, so I want to see everything in the tree.
The logRole
function does take a { hidden }
parameter and by default is set to false
, however the function signature in Typescript does not accept a second parameter.
Suggested solution:
A useful thing would be that hidden was on by default, the function signature would be updated to take the second parameter, and that elements logged that are hidden, report so in the pretty role output.