Skip to content

no-node-access false positive when passing element to a function #1066

@smckinneywwt

Description

@smckinneywwt

Have you read the Troubleshooting section?

Yes

Plugin version

7.6.6

ESLint version

9.33.0

Node.js version

22.12.0

Bug description

When calling user.click(element), if the call occurs in an external function and not a test, no-node-access reports the following error:

Avoid direct Node access. Prefer using the methods from Testing Library.

Steps to reproduce

Create a function that takes user and element as params:

export const click = async (user: UserEvent, element: HTMLElement) => {
  await user.click(element);
};

You will see that await user.click(element); flags an error.

Error output/screenshots

Avoid direct Node access. Prefer using the methods from Testing Library.

ESLint configuration

// Testing Library
{
  files: ['tests/unit/**/*.{js,ts}'],
  ...pluginTestingLibrary.configs['flat/vue'],
},

Rule(s) affected

no-node-access

Anything else?

This started in v7.6.6. It was not a problem in v7.6.5.

No issue flagged with the following code within a test, only when this same behavior is extracted to the function copied in Steps to Reproduce.

await user.click(screen.getByRole('button', { name: 'Submit' }));

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions