Skip to content

False negative for testing-library/prefer-screen-queries #367

@julienw

Description

@julienw

Hey!

When handling the new failures in our projects due to adding testing-library/prefer-screen-queries, I noticed some patterns weren't noticed by the rule. Strangely other similar patterns were noticed.

This pattern is when returning the result of render, and then destructuring in the caller, ie some variations of:

function setup() {
  return render(<Foo />);
}

// Then in a test
const { getByText } = setup();
getByText("foo");

I couldn't find what difference these cases, so I'll rather pinpoint existing code in our project.

This was noticed by the rule:
https://github.com/firefox-devtools/profiler/blob/1c5dfed055f864413b3a62e43ca2d27b074d6108/src/test/components/TrackContextMenu.test.js#L64-L73
And everything in this file
https://github.com/firefox-devtools/profiler/blob/1c5dfed055f864413b3a62e43ca2d27b074d6108/src/test/components/ZipFileTree.test.js#L56-L70
And everything in this file

This wasn't noticed by the rule:
https://github.com/firefox-devtools/profiler/blob/1c5dfed055f864413b3a62e43ca2d27b074d6108/src/test/components/ButtonWithPanel.test.js#L80-L82
(and below in the same file)
https://github.com/firefox-devtools/profiler/blob/1c5dfed055f864413b3a62e43ca2d27b074d6108/src/test/components/CallNodeContextMenu.test.js#L107-L112

There are other examples, please tell me if you want me to give you all cases.

Initially I thought this was because of the somewhat complex setup, but then I was surprised to see that some cases were actually caught by the rule...

Thanks!

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions