-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjestSetup.js
82 lines (72 loc) · 2.66 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
/* globals jest, NativeModules */
/**
* Set up of the testing environment
*/
import nodeFetch from "node-fetch";
import { NativeModules } from "react-native";
// eslint-disable-next-line functional/immutable-data
NativeModules.RNGestureHandlerModule = {
attachGestureHandler: jest.fn(),
createGestureHandler: jest.fn(),
dropGestureHandler: jest.fn(),
updateGestureHandler: jest.fn(),
forceTouchAvailable: jest.fn(),
flushOperations: jest.fn(),
State: {},
Directions: {}
};
/**
* 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 = () => { };
// eslint-disable-next-line functional/immutable-data
Reanimated.useReducedMotion = () => false;
// eslint-disable-next-line functional/immutable-data
Reanimated.useAnimatedReaction = jest.fn();
// eslint-disable-next-line functional/immutable-data
Reanimated.useAnimatedProps = jest.fn();
// eslint-disable-next-line functional/immutable-data
Reanimated.useFrameCallback = jest.fn();
return Reanimated;
});
jest.mock("react-native/Libraries/TurboModule/TurboModuleRegistry", () => {
const turboModuleRegistry = jest.requireActual(
"react-native/Libraries/TurboModule/TurboModuleRegistry"
);
return {
...turboModuleRegistry,
getEnforcing: name => {
if (name === "RNHapticFeedback") {
return null; // or return a minimal mock
}
return turboModuleRegistry.getEnforcing(name);
}
};
});
// eslint-disable-next-line functional/immutable-data
NativeModules.PlatformConstants = NativeModules.PlatformConstants || {
forceTouchAvailable: false
};
jest.mock('react-native/Libraries/EventEmitter/RCTDeviceEventEmitter', () => ({
default: jest.fn()
}));
// 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;
// eslint-disable-next-line functional/immutable-data, no-underscore-dangle
global.__reanimatedWorkletInit = jest.fn();
jest.mock("./src/utils/accessibility", () => ({
useBoldTextEnabled: () => false,
useIOFontDynamicScale: () => ({
dynamicFontScale: 1,
spacingScaleMultiplier: 1
})
}));