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.

prefer-find-by autofix doesn't respect extra code

See original GitHub issue

Plugin version

v5.3.1

ESLint version

v8.14.0

Node.js version

v16.3.0

npm/yarn version

npm v8.9.0

Operating system

macOS v12.3.1

Bug description

The autofix of the rule prefer-find-by doesn’t work correctly when waitFor options are provided, or there is an assertion involved.

Steps to reproduce

  1. Providing waitFor options:
    const button = await waitFor(() => screen.getByText('Count is: 0'), {
        timeout: 100,
      })
    
  2. There is an assertion involved
    await waitFor(() =>
        expect(
          screen.getByRole('button', { name: 'Count is: 0' }),
        ).toBeInTheDocument(),
      )
    

Error output/screenshots

These are fixed as:

  1. Providing waitFor options:
    const button = await screen.findByText('Count is: 0')
    
  2. There is an assertion involved
    await screen.findByRole('button', { name: 'Count is: 0' })
    

ESLint configuration

N/A

Rule(s) affected

prefer-find-by

Anything else?

They should be fixed as:

  1. Providing waitFor options:
    const button = await screen.findByText('Count is: 0', { timeout: 100 })
    
  2. There is an assertion involved
      expect(
        await screen.findByRole('button', { name: 'Count is: 0' }),
      ).toBeInTheDocument(),
    

Do you want to submit a pull request to fix this bug?

Yes

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Belco90commented, Oct 19, 2022

That’s right, but this is referring to findBy* queries, which is a wrapper over waitFor util + getBy* queries. This is mentioned in the official docs (I should have linked this in the ticket description, my bad):

findBy methods are a combination of getBy queries and waitFor. They accept the waitFor options as the last argument (e.g. await screen.findByText(‘text’, queryOptions, waitForOptions)).

So based on this, we should keep the options found in the waitFor util, and pass them as the last argument to findBy* queries. You can reproduce this with the examples I left in the description: the options disappear.

1reaction
Belco90commented, Oct 21, 2022

Reopening since only the first half is done (GitHub automation closed it, my bad).

Read more comments on GitHub >

github_iconTop Results From Across the Web

React typescript: eslint max-length autofix does not work
But seems like my eslint max-lenght auto-fix does not work. I just go warn and when i click the quick its just disable...
Read more >
could not determine executable to run git commit - You.com
Assuming that the remote repository has a copy of the develop branch (your initial description describes it in a local repository, but it...
Read more >
Release Notes - Documentation ・ CoreMedia
If you use these libraries in project code, please check their respective release notes ... doesn't require any additional Studio development anymore.
Read more >
Draft: [RUN ALL RSPEC] Draft: CI decomposition PoC - GitLab
Have a well-written commit message. · Has all tests passing when used on its own (e.g. when using git checkout SHA). · Can...
Read more >
Fishing Buddy : TradeSkill Mods : World of Warcraft AddOns
preferred equipment manager. alt-clicking on an item in your outfit display will clear it ... If your unzip program doesn't let you specify...
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