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

Some more false negative for testing-library/prefer-screen-queries

Open
#391 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hey @Belco90
I just upgraded to the new version that fixed #367, and I am reporting that it indeed reported new cases...but not all of them!

For example these cases aren't reported still: https://github.com/firefox-devtools/profiler/blob/1c5dfed055f864413b3a62e43ca2d27b074d6108/src/test/components/CallNodeContextMenu.test.js#L107-L112

I'm pretty sure this is because of the spread operator. And indeed I reproduced by slightly adjusting one of the smaller testcases:

import * as React from 'react';
import { render } from 'firefox-profiler/test/fixtures/testing-library';

function setup() {
  const result = render(<div />);
  return { ...result };
}

it('detected', async () => {
  const { getByText } = await setup();

  expect(getByText('foo')).toBeInTheDocument(); // detected
});

it('undetected', () => {
  const { getByText } = setup();

  expect(getByText('foo')).toBeInTheDocument(); // undetected
});

Hope this helps :-)

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 reproducing the rule against the cases in src/test/components/CallNodeContextMenu.test.js, lines 107-112, and the reduced setup example using the spread operator. Trace how setup's returned properties are resolved, then verify that both getByText cases are reported while preserving the existing detected case.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript, react, typescript
Domain
testing-qa, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.