Skip to content

testing-library/no-node-access triggered without testing-library imported #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
flip-it opened this issue Apr 13, 2021 · 1 comment
Closed
Labels
duplicate This issue or pull request already exists

Comments

@flip-it
Copy link

flip-it commented Apr 13, 2021

As soon as I access children on an arbitrary object, the error testing-library/no-node-access is triggered, even when testing-library is not used in this file. It's not even in a test file. So essentially adding a new file with content:

const zone = {};
console.log(zone.children);

and then running eslint on it fails with message Avoid direct Node access. Prefer using the methods from Testing Library.

I have seen the utility isTestingLibraryImported but can't find if it's actually used anywhere. Or am I missing something?

My eslint config is something like:

{
    parser: '@babel/eslint-parser',
    plugins: ['ramda', 'jest-dom', 'testing-library'],
    extends: [
        'react-app',
        'airbnb',
        'plugin:ramda/recommended',
        'plugin:jest-dom/recommended',
        'plugin:testing-library/react',
    ]
}
@Belco90
Copy link
Member

Belco90 commented Apr 13, 2021

Hi @flip-it! I recommend you to read this thread, so you can find more context about how to lint only your test files and what improvements we are gonna apply to clarify this situation.

isTestingLibraryImported assumes Testing Library is imported when the modules mechanism from Aggressive Reporting is enabled (which by default is enabled).

Closing this issue in favor of moving any additional discussion to #331

@Belco90 Belco90 closed this as completed Apr 13, 2021
@Belco90 Belco90 added the duplicate This issue or pull request already exists label Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants