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

should getByText return a title?

Open
#593 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • @testing-library/dom version: latest master
  • Testing Framework and version: node, jest 12.x, 26.x
  • DOM Environment:
Relevant code or config:
test('foo', () => {
  renderIntoDocument(` <svg>
  <title data-testid="svg">Close</title>
  <g><path /></g>
</svg>`)

  screen.debug(screen.getByText('Close'))
})

What you did:

called screen.getByText

What happened:

I got back the title... but shouldn't getByText be accessible to everyone? If it's hidden, it won't be accessible to sighted users.

Reproduction:
Problem description:
Suggested solution:

have getByText ignore <title> elements.

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

Reproduce the SVG example using screen.getByText('Close') and inspect the query behavior for the <title> element. Determine whether title elements should be excluded from getByText, then add coverage showing the expected result and run the relevant test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.