cypress-io/cypress-react-unit-test

[Question] Stubbing/Mocking redux hooks in mountHook

fayeed opened this issue · 4 comments

I am trying to unit test a custom hook which also uses redux hook, like useSelector & useDispatch but I am getting an error that the hook is not wrapped in Provider. I am mounting the hook using mountHook but am not sure how to get around the provider issue. Any help is appreciated.

Internally the mountHook call the hook inside a component, so I was wondering if there is a way we can change that, or if there is any other work around to go over this issue.

@bahmutov Yeah sure

@bahmutov added a minimum reproducible example, to provide more context on this issue, react-testing-library provides a config option to provide a wrapper that replaces the default wrapper. You can take a look at this example.

🎉 This issue has been resolved in version 4.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀