vendredi 29 juin 2018

how to test a function which calls 2 other functions with jest and enzyme

I'm using react-dates component in my react project and 'onDatesChange' is a function which is dispatching actions to redux store two times, can someone help me in testing this function with jest and enzyme..

This is DateRangeComponent imported from react-dates.

<DateRangePicker
   startDate={this.props.filters.startDate}
   startDateId={this.state.startDateId}
   endDate={this.props.filters.endDate}
   endDateId={this.state.endDateId}
   onDatesChange={this.onDatesChange}
   focusedInput={this.state.calenderFocused}
   onFocusChange={this.onFocusChange}
   showClearDates={true}
   numberOfMonths={1}
   isOutsideRange={() => false}
/>

And this is my function which is dispatching two actions to the redux store.

onDatesChange = ({ startDate, endDate }) => {
  this.props.dispatch(setStartDate(startDate));
  this.props.dispatch(setEndDate(endDate));
};

How can I test this function in this form. I know, I can test it easily if I refactor it to mapDispatchToProps, which I don't wanna do. thanks

Aucun commentaire:

Enregistrer un commentaire