mercredi 25 octobre 2017

How to test a React component with RouteComponentProps?

I have a component that has props which extend RouteComponentProps that looks like this:

export interface RouteComponentProps<P> {
  match: match<P>;
  location: H.Location;
  history: H.History;
  staticContext?: any;
}

Now, when I use my component in the app, I pass these props to it:

<MyComponent
    match={this.props.match}
    location={this.props.location}
    history={this.props.history}
/>

The props are available already because it's running inside react router.

Now, how do I test this component without match, location, history available?

Do I need to mock them or is it supposed to somehow automatically load them with some helper function?

Aucun commentaire:

Enregistrer un commentaire