xref: /expo/packages/expo-dev-menu/setupTests.ts (revision feef0cca)
1import { cleanup } from '@testing-library/react-native';
2import 'react-native-gesture-handler/jestSetup';
3
4afterEach(cleanup);
5
6jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
7
8jest.mock('react-native-reanimated', () => {
9  const Reanimated = require('react-native-reanimated/mock');
10
11  // The mock for `call` immediately calls the callback which is incorrect
12  // So we override it with a no-op
13  Reanimated.default.call = () => {};
14
15  return Reanimated;
16});
17
18jest.mock('react-native/Libraries/Components/Switch/Switch', () => {
19  const View = require('react-native/Libraries/Components/View/View');
20  const React = require('react');
21  const MockSwitch = React.forwardRef((props, ref) => {
22    return React.createElement(View, { ...props, onPress: props.onValueChange });
23  });
24
25  // workaround to be compatible with modern `Switch` in RN 0.66 which has ESM export
26  // Use `return { default: MockSwitch };` when we drop support for SDK 44
27  MockSwitch.default = MockSwitch;
28
29  return MockSwitch;
30});
31
32jest.mock('./app/native-modules/DevMenu');
33jest.mock('./app/native-modules/DevLauncher');
34
35const MOCK_INITIAL_METRICS = {
36  frame: {
37    width: 320,
38    height: 640,
39    x: 0,
40    y: 0,
41  },
42  insets: {
43    left: 0,
44    right: 0,
45    bottom: 0,
46    top: 0,
47  },
48};
49
50jest.mock('react-native-safe-area-context', () => {
51  return {
52    SafeAreaProvider: ({ children }: any) => children,
53    SafeAreaView: ({ children }: any) => children,
54    useSafeAreaInsets: jest.fn().mockReturnValue(MOCK_INITIAL_METRICS.insets),
55  };
56});
57