testing-library / testing-library/dom-testing-library
Add option to *ByText to search by innerText
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
Describe the feature you'd like:
I'd like to have an includeDescendents option to *ByText which would effectively be the same as searching by innerText (but it's not that simple since it needs to respect the ignore option).
I'm new to testing-library and have more familiarity with Cypress. I was hoping to find similar behaviour to cy.contains.
Suggested implementation:
Describe alternatives you've considered:
cy.contains but this is always an { exact: false} match which is usually less than ideal.
Teachability, Documentation, Adoption, Migration Strategy:
Given this:
<p>
Refer to the
<a
href="https://testing-library.com/docs/dom-testing-library/api-custom-queries"
>Custom Queries</a
>
section for more details.
</p>
Then this:
findByText('Refer to the Custom Queries section for more details.', { includeDescendents: true })
Should match the p node.
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 *ByText query entry points and review how text matching currently handles the ignore option and descendant content. Use the provided findByText example as the acceptance case: the p node should match when includeDescendents is enabled, while exact matching and ignore behavior remain defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100