-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ESLint: Add and enable eslint-plugin-testing-library
#45103
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Size Change: +174 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
84ee369
to
c06928e
Compare
c06928e
to
b912dea
Compare
This one is ready for review now 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of following established recommended practices 👍
In principle, I agree with the reason behind this rule. In practice, we still use Do we have an estimate of how many errors we would need to fix, and how many of those errors would require disabling the rule? |
There are quite a bit of those warnings right now: So one way would be to disable them completely for now and re-enable them once we've fully addressed all that can be addressed. That can help reduce the noise from the warnings. WDYT? |
Sounds like a plan! |
Done in 87df095. This actually makes the PR pretty innocent too, since it introduces no new ESLint warnings or errors, just enables rules that we're already following. Thank you both for taking a look! |
What?
This PR introduces the
eslint-plugin-testing-library
ESLint plugin and enables it for all non-native test files.Why?
It aims to help maintain following the best practices when writing tests with
testing-library
. There's been a discussion around how restrictive those are, and I believe they ensure best practices while being not-so-restrictive, but I'm happy to take feedback.How?
We're enabling the plugin and most its recommended rules for all test files, and excluding all native tests because there's a separate library for it.
I'd suggest we disable a few of the recommended rules for now, because migrating some of them will be tricky and will require more than a few PRs (yes
testing-library/no-container
andtesting-library/no-node-access
, I'm looking at you).Testing Instructions
expect( screen.queryByText( 'Hello' ) ).toBeInTheDocument();
in your test, you'll get an error.Feedback
I'd love some feedback on whether making
no-container
andno-node-access
warnings is okay, or if we should instead disable them completely. My argument towards making them warnings is raising awareness that there's a better way to query for elements, and ideally, get the existing violations fixed as we pass by those test files.