rchgupta
rchgupta

Reputation: 99

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();

Upvotes: 4

Views: 4099

Answers (1)

jpnieto
jpnieto

Reputation: 11

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

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

Upvotes: 1

Related Questions