How to write test cases for mapDispatchToProps in jest and enzyme using reactjs

Viewed 29

How to write the testcases using jest and enzyme for the given code below.

const mapDispatchToProps = dispatch => ({
  getTicketTypes: (request) => dispatch(ticketTypeActions.processTicketTypeRequest(request))
});
1 Answers

I believe its connected to a Redux (-like) state management. I would treat is a black box and would focus on triggering the mapDispatchToProps function in a (dummy) component and checking how the application reacts to it.

I would just follow the best practices here: https://redux.js.org/usage/writing-tests

If thats too vague or difficult: dispatch is received as a function argument, therefore you can create a mock of dispatch and create expectations based on how request is passed to the mock.

Related