testing-library / testing-library/dom-testing-library
`getByTitle` for SVGs canot find `title` if it's not a direct child of `svg`
Open
Nobody has claimed this yet.
bug
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/reactversion: 11.2.7- Testing Framework and version:
jest26x || 27x - DOM Environment: 'jsdom'
16.x
Relevant code or config:
Source: https://testing-library.com/docs/queries/bytitle/
const Test = () => (
<>
<span title="Delete" id="2"></span>
<svg>
<title>Close</title>
<g><path /></g>
</svg>
</>
);
VS
const Test = () => (
<>
<span title="Delete" id="2"></span>
<svg>
<g>
<path>
<title>Close</title>
</path>
</g>
</svg>
</>
);
What you did:
render(<Test/>);
screen.getByTitle('Close');
What happened:
First Component - ✅
Second Component - ❌
TestingLibraryElementError: Unable to find an element with the title: Close.
Problem description:
Testing library cannot find Close because it's not a direct child of svg.
Suggested solution:
I should be able to find Close even if it's not a direct child of svg.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the getByTitle query entry point and reproduce the nested SVG example from the issue, comparing it with the direct-child case. Add or update a regression test so screen.getByTitle('Close') succeeds when the title is nested, then run the relevant JavaScript test suite.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100