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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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