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