dom-testing-library
dom-testing-library copied to clipboard
fix(ByRole): filter by name or description when hidden
What: Fixes the ByRole methods to accept filter hidden elements using name and description. Also fixes the logs to show the accessible name in case of not found error. Related to https://github.com/testing-library/dom-testing-library/issues/846
Why: If we have two hidden elements with the same role we can't filter that using the name. Also when we have hidden elements on logs they don't have the name filled, they are always equal ""
How: By adding the hidden option when use computeAccessibleDescription
and computeAccessibleName
to get the accessible description and name
Checklist:
- [ ] Documentation added to the docs site N/A
- [x] Tests
- [ ] TypeScript definitions updated N/A
- [x] Ready to be merged
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 64e243b87bf12ab6b6ef2bab8414fcb814aca068:
Sandbox | Source |
---|---|
react-testing-library-examples | Configuration |
Codecov Report
Merging #1161 (64e243b) into main (edffb7c) will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## main #1161 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 998 998
Branches 326 326
=========================================
Hits 998 998
Flag | Coverage Δ | |
---|---|---|
node-12 | 100.00% <ø> (ø) |
|
node-14 | 100.00% <ø> (ø) |
|
node-16 | 100.00% <ø> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
Impacted Files | Coverage Δ | |
---|---|---|
src/queries/role.js | 100.00% <ø> (ø) |
|
src/role-helpers.js | 100.00% <ø> (ø) |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
The problem is that the accessible name is different if the element is hidden. See https://github.com/testing-library/dom-testing-library/issues/846#issuecomment-742156607
So this adds a footgun where you just flip hidden
and expect name
to return the same set. I wasn't convinced by https://github.com/testing-library/dom-testing-library/issues/846 fully to implement this so let's add some concrete, high level use cases to https://github.com/testing-library/dom-testing-library/issues/846 first (e.g. what are you testing?).