-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[core] Set up eslint-plugin-testing-library #42909
base: master
Are you sure you want to change the base?
[core] Set up eslint-plugin-testing-library #42909
Conversation
4df5802
to
1db11f8
Compare
Netlify deploy previewhttps://deploy-preview-42909--material-ui.netlify.app/ Bundle size report |
52d240a
to
d46c445
Compare
Not fully reviewing yet, but to note that this PR will need to be canary tested in dependent projects before merging |
d46c445
to
b9c14fc
Compare
b9c14fc
to
1fd0dec
Compare
@@ -685,6 +689,8 @@ describe('<Tabs />', () => { | |||
|
|||
await waitFor(() => { | |||
expect(hasLeftScrollButton(container)).to.equal(true); | |||
}); | |||
await waitFor(() => { |
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.
Only one expect
per waitFor
. Related rule https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/no-wait-for-multiple-assertions.md
This is now ready for review. Keeping it in draft so it's clearer it's not ready to be merged until it's canary tested. |
{ | ||
files: [ | ||
// matching the pattern of the test runner | ||
'*.test.mjs', | ||
'*.test.js', | ||
'*.test.ts', | ||
'*.test.tsx', | ||
], | ||
excludedFiles: ['packages/markdown/**/*', 'test/e2e/**/*', 'test/regressions/**/*'], | ||
extends: ['plugin:testing-library/react'], | ||
rules: { | ||
'testing-library/no-container': 'off', | ||
'testing-library/prefer-screen-queries': 'off', | ||
}, | ||
}, |
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.
Configuring the ESLint plugin using overrides
so it only runs on test files. See docs for more info https://github.com/testing-library/eslint-plugin-testing-library?tab=readme-ov-file#eslint-overrides
@@ -25,6 +25,7 @@ describe('<ClickAwayListener />', () => { | |||
* React bug: https://github.com/facebook/react/issues/20074 | |||
*/ | |||
function render(...args) { | |||
// eslint-disable-next-line testing-library/render-result-naming-convention |
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.
The render-result-naming-convention
rule seems to warn whenever it finds a function/method name that contains "render" 😅
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.
oh 🤦 . Maybe we should just disable this one rule?
@@ -83,6 +83,7 @@ describe('mochaHooks', () => { | |||
// not wrapped in act() | |||
unsafeSetState(1); | |||
// make sure effects are flushed | |||
// eslint-disable-next-line testing-library/no-unnecessary-act | |||
act(() => {}); |
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.
Shouldn't this be async as well?
act(() => {}); | |
await act(async () => {}); |
Perhaps it could make sense to create a await flushEffects()
helper?
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 initially started to await all act
but realized there were too many changes. I decided to await
all act
calls in another PR, but if you think it makes sense to make it all at once I'm ok with it, too.
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.
No, it would be good to do separate as far as I'm concerned.
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.
Perhaps it could make sense to create a await flushEffects() helper?
There is one: flushMicrotasks
in internal-test-utils
act(() => { | ||
button.focus(); | ||
}); | ||
button.focus(); |
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.
Would expect this one to be wrapped in act
.
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.
Whoops! True, not sure why/how I did this. Fixed.
@@ -25,6 +25,7 @@ describe('<ClickAwayListener />', () => { | |||
* React bug: https://github.com/facebook/react/issues/20074 | |||
*/ | |||
function render(...args) { | |||
// eslint-disable-next-line testing-library/render-result-naming-convention | |||
const result = clientRender(...args); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
After chatting with @Janpot, I'll create a separate PR with test changes and leave this one only with the ESLint plugin setup. |
@@ -111,9 +111,7 @@ describe('<AccordionSummary />', () => { | |||
|
|||
// this doesn't actually apply focus like in the browser. we need to move focus manually |
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.
... or use @testing-library/user-event
🙂
1fd0dec
to
ea057c7
Compare
Part of mui/mui-public#173. Sets up eslint-plugin-testing-library and fix related issues.
Two rules have been disabled given the amount of errors reported: