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.

Bug: `no-dom-import` false negatives with several Testing Library imports

See original GitHub issue

Have you read the Troubleshooting section?

Yes

Plugin version

5.3.3

ESLint version

v8.14.0

Node.js version

v16.15.0

package manager and version

npm v8.9.0

Operating system

macOS v12.3.1

Bug description

If there are several Testing Library imports, no-dom-import doesn’t report @testing-library/dom imports if they are other than the first occurrence between Testing Library imports.

Steps to reproduce

This should be reported but it’s not:

import { render } from '@testing-library/react'
import { screen } from '@testing-library/dom'
// ^ this import is not reported since it's not the first Testing Library import

import { App } from '../App'

it('should render a basic demo', () => {
  render(<App />)
  expect(screen.getByText('Hello Parcel + React!')).toBeInTheDocument()
})

Error output/screenshots

N/A

ESLint configuration

N/A

Rule(s) affected

no-dom-import

Anything else?

This is related to how we store the imported Testing Library module in the internal helpers. This only allows one Testing Library module, so the first one found it’s the chosen one for later checks.

I remember mentioning this in another issue/PR, but I can’t remember which one. This is not that simple to fix since we need to store a list of Testing Library modules used rather than a single one, updating all the helpers provided internally too.

After we allow storing several Testing Library modules in our core helpers, we will be able to fix the actual issue reported.

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

Yes

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Belco90commented, Sep 12, 2022

@Belco90 I noticed that you had said that you’d like to submit a PR to fix this. Would you mind if I submit one, since you haven’t done one yet?

I couldn’t work on this, so please feel free to submit a PR to fix it! 🙏

0reactions
Belco90commented, Oct 2, 2022

Alright, the PR is now open! I noticed that other rules (prefer-wait-for and no-manual-cleanup) also use the old util function that returns just the first Testing Library import. I didn’t refactor them to use this new util that returns all Testing Library imports, because I wasn’t sure if there are false negatives with the old implementation. If a refactor is needed, I can work on that too, either on a new PR or #657.

Refactoring those rules would be amazing! Better to open an issue for that so we can discuss the approach properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

False negative for testing-library/prefer-screen-queries #367
Hey! When handling the new failures in our projects due to adding testing-library/prefer-screen-queries, I noticed some patterns weren't ...
Read more >
Reproducable asynchronous bug found in @testing-library/react
In result, my test would like to see if the 'new' value is ever shown. Despite issuing rerender , you will see the...
Read more >
About Queries - Testing Library
Overview​ Queries are the methods that Testing Library gives you to find elements on the page. There are several types of queries ("get",...
Read more >
eslint-plugin-testing-library - npm
This plugin exports several recommended configurations that enforce good practices for specific Testing Library packages. You can find more info ...
Read more >
False positive & false negative in software testing - Testfully
Testfully offers multi-step tests, local & deployed API testing, team collaboration, historical test results and many more features. Import from ...
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