th3rdwave / react-native-safe-area-context

A flexible way to handle safe area insets in JS. Also works on Android and Web!
MIT License
2.08k stars 191 forks source link

Issue with mock: InteractionManager.createInteractionHandle is not a function #477

Closed jamesmcn1 closed 3 months ago

jamesmcn1 commented 3 months ago

Hey guys,

I am trying to unit test a navigation container and stack using jest. I have used the mocking for react-native-safe-area-context that is described in the library:

jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);

However, I am getting an error:

TypeError: _reactNative.InteractionManager.createInteractionHandle is not a function

Test file:

    renderWithProviders(
        <NavigationContainer>
          <HomeMoveStack />
        </NavigationContainer>
      ,
      {
        initialState: {
          session: {
            selectedAccount: 'TEST',
          },
        },
        mocks: [],
      },
    );

// HomeMoveStack

    <Stack.Navigator
        initialRouteName={initialRoute}
        screenOptions={{
          animationEnabled: false,
          headerShown: false,
        }}>
        <Stack.Screen
          name={routes.HOME_MOVE_OUTBOUND}
          component={HomeMoveOutbound}
        />
    </Stack.Navigator>

// renderWithProviders

export const renderWithProviders = (
  ui: ReactElement,
  {initialState, mocks = []}: RenderOptions = {},
): RenderResponse => {
  const store = initStore(initialState);
  const dispatchSpy = jest.spyOn(store, 'dispatch');
  const wrapper = Providers(store, mocks);

  return {...render(ui, {wrapper}), store, dispatchSpy};
};

I am running: "@react-navigation/bottom-tabs": "^6.5.7", "@react-navigation/drawer": "^6.6.2", "@react-navigation/native": "^6.0.8", "@react-navigation/native-stack": "^6.9.12", "@react-navigation/stack": "^6.2.0", "react-native": "^0.72", "react-native-safe-area-context": "^4.9.0",

Anyone know how to resolve this?

Cheers

jacobp100 commented 3 months ago

Looks like a misconfiguration for your jest setup rather than a bug in this repo. If you find a minimal reproduction that shows a bug, fee free to reopen the issue