Skip to content
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

[test] Remove createMount test util #42703

Merged
merged 9 commits into from
Jun 26, 2024

Conversation

aarongarciah
Copy link
Member

@aarongarciah aarongarciah commented Jun 21, 2024

Part of #42454

Warning

A lot of tests have been modified, pay special attention while reviewing. Highly recommended to review commit by commit.

Highlights:

  • Removes the createMount util from @mui/internal-test-utils in favor of createRender.
    • The mount argument in describeConformanceUnstyled calls was unused, it has been removed from all Base UI tests.
    • Adapts tests suites to use createRender instead of createMount.
      • Menu (material)
      • Popover (material)
      • StylesProvider (mui-styles)
      • makeStyles (mui-styles)
  • Removes the findOutermostIntrinsic and wrapsIntrinsicElement from @mui/internal-test-utils. They seem unused across our code bases.

Some of the tests have been updated to not rely on implementation details (e.g. props introspection) now that Enzyme is gone.

@aarongarciah aarongarciah added test core Infrastructure work going on behind the scenes labels Jun 21, 2024
@mui-bot
Copy link

mui-bot commented Jun 21, 2024

Netlify deploy preview

https://deploy-preview-42703--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 8583690

Comment on lines -19 to -37
* returns a function that given the props for the styles object will return
* the css classes
* @param {object} styles argument for `makeStyles`
*/
function createGetClasses(styles) {
const useStyles = makeStyles(styles);
const output = {};

function TestComponent(props) {
output.classes = useStyles(props);
return <div />;
}

return function mountWithProps(props) {
const wrapper = mount(<TestComponent {...props} />);
output.wrapper = wrapper;
return output;
};
}
Copy link
Member Author

@aarongarciah aarongarciah Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This custom setup has been replaced by using the renderHook directly. I think this makes tests easier to read by having less custom abstractions.

Comment on lines +90 to +91
'MUI: The `styles` argument provided is invalid.\nYou are providing a function without a theme in the context.',
'MUI: The `styles` argument provided is invalid.\nYou are providing a function without a theme in the context.',
'Uncaught [TypeError: theme.spacing is not a function',
Copy link
Member Author

@aarongarciah aarongarciah Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why errors are now duplicated, probably due to effects running twice now that renderHook is used. We pass strict: false to createRenderer (and to createMount before) in this test suite. Maybe we could look into creating our own renderHook wrapper with this option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package is not compatible with strict mode, so yes, we need to have that option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can tackle this in another PR to not make this PR even bigger.

expect(sheetsRegistry.registry.length).to.equal(2);
expect(sheetsRegistry.toString()).to.equal(`.makeStyles-root-2 {
color: white;
background-color: black;
}`);

act(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fireEvent already handles act for us.

@aarongarciah aarongarciah marked this pull request as ready for review June 21, 2024 14:47
@DiegoAndai DiegoAndai mentioned this pull request Jun 21, 2024
4 tasks
@DiegoAndai DiegoAndai added the React 19 support PRs required to support React 19 label Jun 21, 2024
@aarongarciah aarongarciah mentioned this pull request Jun 24, 2024
15 tasks
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @aarongarciah! I only have one question: #42703 (comment)

@aarongarciah aarongarciah merged commit 53899d7 into mui:next Jun 26, 2024
21 checks passed
@aarongarciah aarongarciah deleted the remove-create-mount branch June 26, 2024 16:34
@aarongarciah aarongarciah mentioned this pull request Jul 5, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes React 19 support PRs required to support React 19 test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants