Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

result.current is null when using renderHook () Custom Hook to test custom hook in react-native using jest and testing-library

For My project I am using one custom hook for navigation some of my screens as from one screen to another screen based on the parameters provide to the function of custom hook. How could I Unit Test it for React Native Custom

const {result} = renderHook(() => {useShoppingCartNavigator()});

The problem is I am getting result.current as void and unable to call function of the hook

But according to the doc it should be like

result.current.customHookFn();
like image 520
rchgupta Avatar asked Nov 19 '25 18:11

rchgupta


1 Answers

The callback inside your renderHook is not returning anything because you wrapped your customHook on curlybraces. It should be

const {result} = renderHook(() => useShoppingCartNavigator());
like image 113
jpnieto Avatar answered Nov 22 '25 05:11

jpnieto