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

Allow saving "within" to variable for rule "Suggest using screen while querying (testing-library/prefer-screen-queries)"

Open
#372 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

According to the rule using

within(screen.getByTestId('section')).getByText('foo');

is allowed.

However, saving the result to a variable

const context = within(screen.getByTestId('section')).getByText('foo');

to re-use it, results in the warning.

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 at the implementation of the testing-library/prefer-screen-queries rule and reproduce the two examples from the issue. Trace how direct within(...) calls differ from values saved to a variable, then update the rule so the variable form is accepted and verify that the original warning still applies where appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, typescript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.