I'm trying to create a unit test for a component in which I have a WebView.
The problem is that inside this component I call the reload() function of the WebView.
And when I run the test I get this error:
Invariant Violation: nodeHandle expected to be non-null
107 | useCallback(() => {
108 | if (navigation.getState().index === 0) {
> 109 | webviewRef.current.reload();
| ^
110 | }
111 | }, [webviewRef, navigation])
112 | );
I tried to mockup the reload() function following an example that I've found on Jest site in this way:
jest.mock('react-native-webview', () => {
const RealComponent = jest.requireActual('react-native-webview');
RealComponent.reload = jest.fn();
return RealComponent;
});
But I'm getting the exact same error message. It seems that jest isn't picking my mockup.
How can I mockup the reload() function of WebView?