-
Notifications
You must be signed in to change notification settings - Fork 471
Add new getByRole queryselector. #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Funny, I was thinking something similar now after the recent discussion in testing-library/jest-dom#55. It would be a nice addition. |
Thanks for the thorough feature request @JeffBaumgardt! I'm in favor of this. Would you like to implement it? |
Can do I'll have a PR later today. |
4 tasks
Closed via #94 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the feature you'd like:
A new querySelector to select elements based on role. I have a dialog that while I can query inside the dialog just fine I cannot first a click to close the dialog because all the current queries target elements inside the dialog so the out of bounds click handlers do not fire.
Suggested implementation:
const queryAllByRole = queryAllByAttribute.bind(null, 'role')
Describe alternatives you've considered:
I'm using Material UI where there is a lot of abstraction in DOM that I can't put data-testid on the outer dialog. So targeting it by testid won't work for triggering the onClose event.
The only thing I've considered is writing the
const dialogConstainer = container.querySelector('[role="dialog"]')
And then writing assertions from there.
Teachability, Documentation, Adoption, Migration Strategy:
This is a non breaking change as it is only an addition to the existing query set.
getByRole
A shortcut to
container.querySelector(`[role="${yourRole}"]`)
(and italso accepts a
TextMatch
).The text was updated successfully, but these errors were encountered: