1import { cleanup } from '@testing-library/react-native';
2
3global.fetch = jest.fn().mockResolvedValue({
4  ok: true,
5  json: () => Promise.resolve({}),
6  text: () => Promise.resolve(''),
7});
8
9afterEach(cleanup);
10
11jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
12
13jest.mock('react-native-reanimated', () => {
14  const Reanimated = require('react-native-reanimated/mock');
15
16  // The mock for `call` immediately calls the callback which is incorrect
17  // So we override it with a no-op
18  Reanimated.default.call = () => {};
19
20  return Reanimated;
21});
22
23jest.mock('react-native/Libraries/Components/Switch/Switch', () => {
24  const View = require('react-native/Libraries/Components/View/View');
25  const React = require('react');
26  function MockSwitch(props) {
27    return React.createElement(View, { ...props, onPress: props.onValueChange });
28  }
29
30  // workaround to be compatible with modern `Switch` in RN 0.66 which has ESM export
31  // Use `return { default: MockSwitch };` when we drop support for SDK 44
32  MockSwitch.default = MockSwitch;
33
34  return MockSwitch;
35});
36
37jest.mock('./bundle/native-modules/DevLauncherInternal');
38jest.mock('./bundle/native-modules/DevLauncherAuth');
39jest.mock('./bundle/native-modules/DevMenuPreferences');
40jest.mock('./bundle/providers/QueryProvider');
41
42const MOCK_INITIAL_METRICS = {
43  frame: {
44    width: 320,
45    height: 640,
46    x: 0,
47    y: 0,
48  },
49  insets: {
50    left: 0,
51    right: 0,
52    bottom: 0,
53    top: 0,
54  },
55};
56
57jest.mock('react-native-safe-area-context', () => {
58  return {
59    SafeAreaProvider: ({ children }: any) => children,
60    SafeAreaView: ({ children }: any) => children,
61    useSafeAreaInsets: jest.fn().mockReturnValue(MOCK_INITIAL_METRICS.insets),
62  };
63});
64
65jest.mock('@react-navigation/native', () => {
66  const actualRequire = jest.requireActual('@react-navigation/native');
67  return {
68    ...actualRequire,
69    useNavigation: jest.fn(),
70  };
71});
72