mui-public
mui-public copied to clipboard
[code-infra] Add react-testing-library eslint plugin
configure eslint-plugin-testing-library and fix issues
See https://github.com/mui/mui-toolpad/pull/3648 as an implementation example.
Could also be helpful in:
- [ ] 1. #174
- [ ] 2. Use
screenat the import level, not the mounting point level:
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
test('renders content correctly', async () => {
- const { getByText } = render(<AppProvider>Hello world</AppProvider>);
+ render(<AppProvider>Hello world</AppProvider>);
- expect(getByText('Hello world')).toBeTruthy();
+ expect(screen.getByText('Hello world')).toBeTruthy();
});
});
For example https://github.com/mui/material-ui/pull/41061#discussion_r1632481628
- [ ] 3. Use
userat the import level, not the mounting point level: https://github.com/mui/mui-x/pull/14142#discussion_r1739138251. Actually maybe not: https://github.com/mui/material-ui/pull/43804#discussion_r1765458889.
Now that we're experimenting with vitest, it looks like using global screen (and global cleanup) prevents our tests from running in parallel. We should actually do the opposite of their recommendation if we want to strictly isolate our tests 😄
Are they mounting multiple components on the same jsdom instance in the same JavaScript context? I would expect that Vitest uses multiple node processes, and hence it doesn't matter. Or can we assign the right jsdom instance to the screen API with a mutation?
Are they mounting multiple components on the same jsdom instance in the same JavaScript context? I would expect that Vitest uses multiple node processes, and hence it doesn't matter. Or can we assign the right jsdom instance to the screen API with a mutation?
Vitest uses multiple processes, that works, but seems to be about 3x slower than mocha (will have to investigate further). I tried disabling their isolation but it acts too weird, even when disabling the per-file parallelism. Probably a dead end for now, yes...
Everything is prepared from infra side, we need to enable it per repository and fix all the issues that will appear.