What is the best approach to test custom hooks, when u are doing component testing and custom hooks dispatch actions and change redux state. For example, I have custom hook which is called on onChange or onClick. I like to simulate the click method, but calling the custom hook, even ends with success and in console.log I can see the changes, checking for the changed state, returns default state.
function useButtonCallback = () => {
const dispatch = useDispatch();
return React.useCallback(() => {
dispatch(...);
}, [dispatch]);
}
const buttonCallback = useButtonCallback();
<Button onClick={() => buttonCallback(...)}
component.button.onClick();
component.update(); // waiting for re-render
// returns false
expect(store.getState().someState.stateBoolean).toBe(true);
BR,