question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow queries to take optional filter function

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mhesscommented, Jun 10, 2022

I also end up waiting on a button to become enabled a lot like this:

let button;
await waitFor(() => {
  button = screen.getByRole('button', {name: 'foo'});
  expect(button).toBeEnabled()
});
userEvent.click(button);

I would find a lot of value in either a interface like @juanca proposed

await screen.findByLabelText('some button', { filter: (element) => !!element.disabled });

or adding an option to waitFor that only runs the callback on dom mutations

1reaction
nickmccurdycommented, Jul 8, 2020
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found