How to pass context down to the Enzyme mount method to test component which includes Material UI component?

后端 未结 2 828
情话喂你
情话喂你 2020-12-30 20:06

I am trying to use mount from Enzyme to test my component in which a several Material UI component are nested. I get this error when running the test:

<

2条回答
  •  我在风中等你
    2020-12-30 20:08

    this is my handy method to test Material UI with shallow and mount

    ...
    import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
    import getMuiTheme from 'material-ui/styles/getMuiTheme';
    
    const muiTheme = getMuiTheme();
    const shallowWithContext = (node) => shallow(node, {context: {muiTheme}, childContextTypes: {muiTheme: PropTypes.object}});
    
    const mountWithContext = (node) => mount(
      node, {context: {muiTheme}, childContextTypes: {muiTheme: PropTypes.object}}
    );
    
    
    // now you can do
    const wrapper = shallowWithContext( 'test'} />);

提交回复
热议问题