jest mockImplementation does not work in React navigation (React Nactivate)

Asked

Viewed 18 times

0

I have the following code:

jest.mock('@react-navigation/native', () => {
  return {
    useNavigation: mockedNavigation,
  };
});
...
 it('should pass the test', async () => {
     mockedNavigation.mockImplementation(() => ({
      isFocused: () => false,
    }));
 })

When I run the test I get an error telling me that useNavigation is not a function. However with a simple change the test works:

jest.mock('@react-navigation/native', () => {
  return {
    useNavigation: () => ({
      isFocused: () => false,
    }),
  };
});

What I did in the above code was simply put the implementation of useNavigation within the jest.mock. What I would like to know is why the first example does not work and returns me the error of:

useNavigation is not a Function

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.