Skip to content

[test] Improve the guide documentation page #17070

@liogate

Description

@liogate

Hello,

I've an issue while reading the documentation of material-ui:

https://material-ui.com/guides/testing/#createmount-options-mount

I can't fully understand how to write my tests with custom styles and with this exemple:

import { createMount } from '@material-ui/core/test-utils';
import { MuiThemeProvider } from '@material-ui/core/styles';

describe('<MyComponent />', () => {
  let mount;

  function MySuccessButton({ children }) {
    return (
      <MuiThemeProvider theme={{ success: { main: '#fff' } }}>
        {children}
      </MuiThemeProvider>
    );
  }

  before(() => {
    mount = createMount();
  });

  after(() => {
    mount.cleanUp();
  });

  it('should work', () => {
    const wrapper = mount(<MockedTheme><MySuccessButton /></MockedTheme>);
  });
});

Here is some questions:

  • What is MockedTheme, how and where is it ?
  • Where MyComponent should be mounted ?
  • Did you plan for a TypeScript version of your tests ?

While testing, I ran into this issue:

Error: Uncaught [TypeError: theme.spacing is not a function]

Thank you for your help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeIntroduces changes that are not backward compatible.docsImprovements or additions to the documentation.test

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions