quisi.do
1 min readAug 12, 2020

--

There are two options.

First, my preferred method, would be to abstract away whatever part of your `useComponentName` hook is using the Redux state. Instead of `const value = useSelector(state => state.value)`, convert that into its own hook like `useValue()`. To test `useComponentName`, you just mock `useValue` to return whatever valeu you want, and you need not worry about mounting the global state. This is valuable if you ever intend on replacing the source of truth for this state, such as moving it to a different global state provider (like ReactN, MobX, or Context API) or source (like URL, local storage, or module state).

Second, a method that may also be appropriate, is to use the second parameter of `renderHook`. Check the docs for testing-library, and you'll find the second parameter accepts a `wrapper` method that is useful for mounting context providers, such as Redux's.

--

--

quisi.do
quisi.do

No responses yet