Skip to content

testing-library/no-node-access breaks for querySelector #814

@rolintoucour

Description

@rolintoucour

Have you read the Troubleshooting section?

Yes

Plugin version

v5.0.1

ESLint version

v8.46.0

Node.js version

20.5.0

package manager and version

yarn 1.22.19

Operating system

Ubuntu 22.04

Bug description

I defined the following check to ensure an element with the given id is not present:

expect(renderResult.container.querySelector('#my-id')).toBeFalsy();

The rule "testing-library/no-node-access" is not ok with it, whereas from document nothing should break:

"This rule aims to disallow DOM traversal using native HTML methods and properties, such as closest, lastChild and all that returns another Node element from an HTML tree."

(or I misunderstood this understood).

Steps to reproduce

Apply the previous code snippet

Error output/screenshots

No response

ESLint configuration

{
"extends": [
"react-app",
"react-app/jest"
],
"rules": {
"import/no-anonymous-default-export": "off"
}
}

Rule(s) affected

testing-library/no-node-access

Anything else?

No response

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

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriagePending to be triaged by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions