[internal] Set up eslint-plugin-testing-library#42909
[internal] Set up eslint-plugin-testing-library#42909aarongarciah wants to merge 3 commits intomui:masterfrom
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
| await waitFor(() => { | ||
| expect(hasLeftScrollButton(container)).to.equal(true); | ||
| }); | ||
| await waitFor(() => { |
There was a problem hiding this comment.
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.
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
| * 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.
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.
oh 🤦 . Maybe we should just disable this one rule?
| unsafeSetState(1); | ||
| // make sure effects are flushed | ||
| // eslint-disable-next-line testing-library/no-unnecessary-act | ||
| act(() => {}); |
There was a problem hiding this comment.
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.
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.
No, it would be good to do separate as far as I'm concerned.
There was a problem hiding this comment.
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.
Would expect this one to be wrapped in act.
There was a problem hiding this comment.
Whoops! True, not sure why/how I did this. Fixed.
| */ | ||
| 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. |
| // simulate pointer device | ||
| fireEvent.mouseDown(document.body); | ||
|
|
||
| // this doesn't actually apply focus like in the browser. we need to move focus manually |
There was a problem hiding this comment.
... 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: