Skip to content

prefer-screen-queries and render-result-naming-convention have contradictory messages #777

Open
@abejfehr

Description

@abejfehr

What rule do you want to change?

prefer-screen-queries or render-result-naming-convention

Does this change cause the rule to produce more or fewer warnings?

More warnings

How will the change be implemented?

Say that someone has the following code:

const view = render(...);

...

view.getByText(...);

The lint rule that gets triggered is prefer-screen-queries with the message:

Avoid destructuring queries from render result, use screen.getByText instead

So naively, someone might think to rename the result of render from view to screen to satisfy the message.

But instead, you get this new lint warning from render-result-naming-convention:

screen is not a recommended name for render returned value. Instead, you should destructure it, or name it using one of: view, or utils

which might lead one to believe that there's no satisfying both rules.

Obviously the actual solution is to import screen from @testing-library/... but that's never explicitly mentioned anywhere.

Additionally, the first rule says not to destructure the result of render, but the second rule advocates for it which is contradictory

Example code

N/A

How does the current rule affect the code?

N/A

How will the new rule affect the code?

N/A

Anything else?

These forms are way too restrictive

Do you want to submit a pull request to change the rule?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions