testing-library / testing-library/dom-testing-library
Allow queries to take optional filter function
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:
A common pattern that I've been using is:
const element = getByText(...);
expect(element).toBeVisible();
However, it may be the case that there are invisible elements that match the first selector, leading to a thrown error since multiple elements were found. It would be much nicer to be able to write something like:
const element = getByText(..., {filter: isVisible}); // It would also be nice for jest-dom to export `isVisible`
Describe alternatives you've considered:
If theisVisible use-case is by far the most common, then it could be sufficient to export queryVisibleBy* methods directly.
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
The issue names the getByText query, an optional filter function, and the possible isVisible export from jest-dom, but it names no implementation files or tests. Start by tracing the query API and existing visibility behavior; done should include an agreed filter design and resolve whether visibility helpers or queryVisibleBy* methods are part of the feature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100