Allow queries to take optional filter function
See original GitHub issueDescribe 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Using optional filters | Algolia
Learn how to use optional filters to modify your custom ranking. ... Although you can only filter at query time, you can test...
Read more >Proper way to handle 'optional' where clause filters in SQL?
Let's say you have a stored procedure, and it takes an optional parameter. You want to use this optional parameter in the SQL...
Read more >Optional filtering in a SQL query - Oracle Communities
Say I want to write a stored procedure on the EMP table, which would return NAME, DEPT, SALARY, IS_ACTIVE of an employee (record...
Read more >Excel Dynamic Arrays: FILTER for Optional and Required Fields
The new FILTER function is fantastic, but I wondered how can I make an optional field?Sometimes we do searches and want to look...
Read more >MYSQL - Querying a table with optional filters and default value
I would like to create a query that can receive generic filter (optional) parameters and fetches a single row per key accordingly (when ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also end up waiting on a button to become enabled a lot like this:
I would find a lot of value in either a interface like @juanca proposed
or adding an option to
waitFor
that only runs the callback on dom mutationsI believe this was a comment on getByRole https://github.com/testing-library/dom-testing-library/issues/684#issuecomment-655203800