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

后端 未结 2 829
情话喂你
情话喂你 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:33

    Try adding childContextTypes in the mount options:

    return mount(
      , {
        context: {muiTheme},
        childContextTypes: {muiTheme: React.PropTypes.object}
      }
    );
    

    By doing it you set the Enzyme wrapper to make the muiTheme available to it's children through the context.

提交回复
热议问题