dom-testing-library icon indicating copy to clipboard operation
dom-testing-library copied to clipboard

fix(ByRole): filter by name or description when hidden

Open viniciuslagedo opened this issue 2 years ago • 3 comments

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

viniciuslagedo avatar Aug 31 '22 13:08 viniciuslagedo

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

codesandbox-ci[bot] avatar Aug 31 '22 13:08 codesandbox-ci[bot]

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

codecov[bot] avatar Oct 05 '22 13:10 codecov[bot]

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?).

eps1lon avatar Oct 31 '22 08:10 eps1lon