score:9

Accepted answer

There are multiple ways you can do so. AFAIK:

  • You can mock useDispatch hook to return your own fake dispatch function. I used in my test code for my own React library to help with managing binding dispatch to actions. Here it is hooks.test.tsx.

  • Since you are wrapping your component with a test React store, you can also replace store.dispatch with a fake function directly. See here for a discussion.

Benefit of the first one is that you can easily mock more stuff from react-redux as needed.


Related Query

More Query from same tag