testing-library / testing-library/dom-testing-library

Ability to query a video and still respect the accessibility tree

Open
#1,096 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

Describe the feature you'd like:

It is not possible to query for a video using the *ByRole queries, but these are the only queries which respect the accessibility tree. This means that if you have a video element that is supposed to be hidden, you cannot test it in the same way that you would test other hidden elements. Allowing other queries to opt-in to respecting the accessibility tree was discussed in https://github.com/testing-library/dom-testing-library/issues/929, but this specific case of finding a video was not brought up.

Suggested implementation:
render(<div aria-hidden={true}>
   <video src="abc" aria-label="The Video" />
</div>)

expect(screen.queryByLabelText("The Video", { hidden: false } )).toBe(null)
Describe alternatives you've considered:

The current workaround would have to be something like this, where the developer would need to find the nearest parent that is hidden, which makes the tests too familiar with the layout of the html IMHO

render(<div aria-hidden={true}>
   <video src="abc" aria-label="The Video" />
</div>)

const video = screen.queryByLabelText("The Video")

expect(video.parentElement).toHaveAttribute('aria-hidden', 'true')
Teachability, Documentation, Adoption, Migration Strategy:

This would only require adding the new option hidden to all queries besides *ByRole. The option would default to true.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing *ByRole hidden-option behavior and the queryByLabelText example in this issue, then read the discussion in issue 929. The change is complete when non-role queries can opt into accessibility-tree filtering with a hidden option that defaults to true, and the video example returns null.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.