-
Notifications
You must be signed in to change notification settings - Fork 147
Shouldn't prefer-screen-queries takes into account querySelector? #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi! Thanks for opening this issue 😃 This rule is supposed to enforce the usage of Having said that, this rule should fail because it's using the returned value from a In that sense, I think // **incorrect**
const utils = render(<Component />);
utils.container.querySelector('div');
// **correct**
render(<Component />);
screen.container.querySelector('div'); Does that make sense? So I would consider this a bug, as a scenario of not correctly detecting the lack of usage of screen. For disabling the usage of DOM selectors, we should probably go for another rule. I think that one will be an important addition of this plugin |
I think this can be taken broader, and that we can add a new rule that prohibits the usage of |
I got it and it makes sense for me, though I think we should make this broader and force the user to use the best-practices selectors somehow. Can I take a look at this bug? Thanks for that. |
I can't simulate this bug anymore. Probably, the test I was running earlier was not using the I'll close this issue, though I think we should make this broader. Sorry for that. |
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 const utils = render(<Component />);
utils.container.querySelector('div'); is an invalid scenario. This rule ( render(<Component />);
screen.container.querySelector('div'); Then, another rule should probably enforce whether to use or not Good find btw 😃 If you like, feel free to take a look at this bug and open a PR. |
Yes, there is a bug. I made some mistake earlier trying to reproduce this, I can reproduce now. I'll try to solve this. |
Continuing with the discussion of this bug, we should also consider (besides container and debug) the other properties that are available in |
🎉 This issue has been resolved in version 3.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Reverted due to
is a valid scenario now (will make another PR to add it as a valid one) |
prefer-screen-queries
is not taken into account that the user can do this: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?
The text was updated successfully, but these errors were encountered: