Shouldn't prefer-screen-queries takes into account querySelector?
See original GitHub issueprefer-screen-queries
is not taken into account that the user can do this:
const utils = render(<Component />);
utils.container.querySelector('div');
This kind of selector can lead the user to a bad pattern of tests according to the testing-library.
I don’t understand eslint under the hood, but I propose to change the prefer-screen-queries
to take the snippet above into account as a bad pattern.
What do you guys think about that?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Document.querySelector() - Web APIs | MDN
An Element object representing the first element in the document that matches the specified set of CSS selectors, or null is returned if...
Read more >javascript - Why can't I use querySelector on a parentElement ...
No. from docs: The querySelector() method of the Element interface returns the first element that is a descendant of the element on which...
Read more >I'm trying to use document.querySelector by it doesn't seem to ...
Hi, the better option here is to use toe getElementById() method. The reason for this is that specific id's should be used only...
Read more >Using querySelector and querySelectorAll With Modern ...
querySelector () accepts a string which it uses as a CSS selector for selecting elements in the DOM. The first element that matches...
Read more >How to use CSS Selector - QuerySelector, QuerySelectorAll
In the following example we use CSS Element Selector to find the first ... In the following C# example, QuerySelector() method takes as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, there is a bug. I made some mistake earlier trying to reproduce this, I can reproduce now.
I’ll try to solve this.
Hey, @lourenci , I’m reopening your issue.
despite the discussion about whether we should enforce or not using the querySelector and all that, this code in your first comment
is an invalid scenario.
This rule (
prefer-screen-queries
) should detect thatscreen
is not used and enforce it to fail, as the correct scenario should beThen, another rule should probably enforce whether to use or not
container.querySelector
- but this probably is a bug ofprefer-screen-queries
Good find btw 😃
If you like, feel free to take a look at this bug and open a PR.