-
Notifications
You must be signed in to change notification settings - Fork 105
/
jestSetup.js
141 lines (118 loc) · 4.57 KB
/
jestSetup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* eslint-disable @typescript-eslint/no-var-requires */
// eslint-disable-next-line no-redeclare
/* globals jest, NativeModules, require, global */
/**
* Set up of the testing environment
*/
import mockAsyncStorage from "@react-native-async-storage/async-storage/jest/async-storage-mock";
import mockClipboard from "@react-native-clipboard/clipboard/jest/clipboard-mock.js";
import nodeFetch from "node-fetch";
import { NativeModules } from "react-native";
import mockRNDeviceInfo from "react-native-device-info/jest/react-native-device-info-mock";
import mockRNCameraRoll from "@react-native-camera-roll/camera-roll/src/__mocks__/nativeInterface";
import mockZendesk from "./ts/__mocks__/io-react-native-zendesk.ts";
jest.mock("@pagopa/io-react-native-zendesk", () => mockZendesk);
jest.mock("@react-native-async-storage/async-storage", () => mockAsyncStorage);
jest.mock("@react-native-community/push-notification-ios", () => jest.fn());
jest.mock("@react-native-cookies/cookies", () => jest.fn());
jest.mock("react-native-share", () => jest.fn());
jest.mock("@react-native-clipboard/clipboard", () => mockClipboard);
jest.mock("@react-native-camera-roll/camera-roll", () => mockRNCameraRoll);
/**
* adds as for documentation suggestion
* https://docs.swmansion.com/react-native-reanimated/docs/1.x.x/getting_started/#testing
*/
jest.mock("react-native-reanimated", () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Reanimated = require("react-native-reanimated/mock");
// The mock misses the `addWhitelistedUIProps` implementation
// So we override it with a no-op
// eslint-disable-next-line functional/immutable-data,@typescript-eslint/no-empty-function
Reanimated.default.addWhitelistedUIProps = () => {};
return Reanimated;
});
jest.mock("react-native-blob-util", () => ({
DocumentDir: () => jest.fn(),
polyfill: () => jest.fn()
}));
// eslint-disable-next-line functional/immutable-data
NativeModules.PlatformConstants = NativeModules.PlatformConstants || {
forceTouchAvailable: false
};
// We need to override the global fetch and AbortController to make the tests
// compatible with node-fetch
const {
AbortController
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require("abortcontroller-polyfill/dist/cjs-ponyfill");
// eslint-disable-next-line @typescript-eslint/no-explicit-any,functional/immutable-data
global.fetch = nodeFetch;
// eslint-disable-next-line @typescript-eslint/no-explicit-any,functional/immutable-data
global.AbortController = AbortController;
jest.mock("remark-directive", () => jest.fn());
jest.mock("remark-rehype", () => jest.fn());
jest.mock("rehype-stringify", () => jest.fn());
jest.mock("rehype-format", () => jest.fn());
jest.mock("unist-util-visit", () => jest.fn());
jest.mock("hastscript", () => jest.fn());
jest.mock("react-native-device-info", () => mockRNDeviceInfo);
// eslint-disable-next-line no-underscore-dangle, functional/immutable-data
global.__reanimatedWorkletInit = () => jest.fn();
jest.mock("@gorhom/bottom-sheet", () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const rn = require("react-native");
return {
__esModule: true,
BottomSheetModal: rn.Modal,
BottomSheetScrollView: rn.ScrollView,
TouchableWithoutFeedback: rn.TouchableWithoutFeedback,
useBottomSheetModal: () => ({
dismissAll: jest.fn()
}),
namedExport: {
...require("react-native-reanimated/mock"),
...jest.requireActual("@gorhom/bottom-sheet")
}
};
});
jest.mock("react-native-device-info", () => mockRNDeviceInfo);
jest.mock("react-native-pdf", () => jest.fn());
jest.mock("react-native-permissions", () =>
require("react-native-permissions/mock")
);
/*
* Turbo modules mocks.
*/
jest.mock("react-native/Libraries/TurboModule/TurboModuleRegistry", () => {
const turboModuleRegistry = jest.requireActual(
"react-native/Libraries/TurboModule/TurboModuleRegistry"
);
return {
...turboModuleRegistry,
getEnforcing: name => {
// List of TurboModules libraries to mock.
const modulesToMock = ["RNDocumentPicker"];
if (modulesToMock.includes(name)) {
return null;
}
return turboModuleRegistry.getEnforcing(name);
}
};
});
jest.mock("react-native-webview", () => {
const React = require("react");
const { View } = require("react-native");
const WebView = props => <View {...props} />;
return {
WebView,
default: WebView,
__esModule: true
};
});
jest.mock("mixpanel-react-native", () => ({
__esModule: true,
default: () => jest.fn(),
Mixpanel: jest.fn(() => ({
init: jest.fn()
}))
}));