有谁知道使用null时使安装的组件返回Enzyme.mount(或类似内容)的可接受方法吗?

用例

我有一个包装在n个高阶组件中的组件。我想实际上是mount组件而不是shallow,因为我想测试componentDidMount调用了预期的东西。

我的挂载功能/测试是这样的:

const component = <ApplicationsShowRoute />;
const { store } = mountSetup(component);
expect(store.getActions()).toEqual([ { type: 'API_REQUEST' } ]);


挂载此文件时,我宁愿不必担心呈现的内容(子组件中的错误等)。



export class ApplicationsShowRouteRaw extends Component {

  componentDidMount() {
    const { uuid } = this.props.match.params;

    this.props.fetchShowRoute(uuid);
  }

  props: Props

  render() {
    const { application, match } = this.props;

    return isEmpty(application) || application.Uuid !== match.params.uuid ? (
      <FullPageLoader />
    ) : (
      <ApplicationsShow
        application={application}
      />
    );
  }
}

export const mapStateToProps = (state: Object) => ({
  application: getShowRoute(state),
});

export const mapDispatchToProps = (dispatch: Function) => ({
  fetchShowRoute: (uuid: string) => dispatch(fetchShowRoute(uuid)),
});

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(ApplicationsShowRouteRaw);

最佳答案

如果要使用所有生命周期方法进行浅显示,则可以将shallowlifecycleExperimental选项设置为true

09-30 13:34
查看更多