-
Notifications
You must be signed in to change notification settings - Fork 471
feat(byRole): Add description filter #1120
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
feat(byRole): Add description filter #1120
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2c18fc5:
|
Codecov Report
@@ Coverage Diff @@
## main #1120 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 970 985 +15
Branches 316 322 +6
=========================================
+ Hits 970 985 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks!
We need documentation in https://github.com/testing-library/testing-library-docs/edit/main/docs/queries/byrole.mdx (under "Options") for this to be mergable.
Hey @eps1lon, you mention to add the new option under the Options section but I noticed the Should I move that explanation to the Options section? Thanks! |
We should move the |
const domString = prettyDOM(el.cloneNode(false)) | ||
|
||
if (includeDescription) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we originally decide to always include it to help people discover the name
option (would have to check the original PR though).
Though I don't think this necessarily applies to description
since it's
- more likely to not be set
- quite noisy (concerning length) if you don't care about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look at the history.
If we indeed decided to always include it (which makes sense imho), I'll remove the code where we now add the includeName
argument.
Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very well crafted PR. Thanks!
🎉 This PR is included in version 8.13.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks for accepting this little feature and for your help 👍 |
I had some tests like this: <button title="this is the title">click me</button>
screen.getByRole('button', { name: /this is the title/i }) // <- before it was getting by its title now it only gets by its children <button title="this is the title">click me</button>
screen.getByRole('button', { name: /this is the title/i }) // <- failing
screen.getByRole('button', { name: /click me/i }) // <- OK is this problem related to this change? thanks! |
What:
Add a new
description
option toByRole
queries.This helps finding elements which are aria described.
Why:
We were implementing a React component to display the usual popup notifications and, when reading about accessibility considerations, we found we should use
ariadialog
role and we also should usearia-describedby
to reference the message (spec documentation).When writing some tests we wanted to have one where we could close an specific notification when a list of them were rendered in a view.
ByRole
queries currently support filtering results by accessible name, but no filtering by accessible description.How:
Since this project is already using the dom-accessibility-api dependency to resolve the accessible name and that library also expose a function to resolve the accessible description, I would like to introduce this proposal where we implement filtering by description when using
ByRole
queries.Given some HTML markup like this one:
Now we can find
alertdialog
elements with this kind of query:I used this PR (when
name
filtering was added toByRole
queries) to guide my proposed implementation.I just wanted to create the proposal with some actual code so maybe it's easier to reason about and maybe there are other thing to take into account that we might discuss as a follow-up of this starting point.
Checklist:
docs site
References
These are the documents I used as reference for this proposal:
alertdialog
spec