testing-library / testing-library/eslint-plugin-testing-library

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

Open
#777 0 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
1.1k
Forks
168
Avg merge
15h 44m
Merged PRs (30d)
14

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementations and tests for prefer-screen-queries and render-result-naming-convention, then read how their current messages and naming guidance are asserted. Done means the two rules provide consistent, actionable guidance for the render result and screen import without suggesting mutually contradictory fixes.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, typescript
Domain
testing-qa, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.