Repository navigation
Expand file tree
/
Copy pathjest.setup.js
More file actions
145 lines (131 loc) · 4.66 KB
/
Copy pathjest.setup.js
File metadata and controls
145 lines (131 loc) · 4.66 KB
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
142
143
144
145
/* eslint-env jest */
const mockAsyncStorage = {
getItem: jest.fn(() => Promise.resolve(null)),
setItem: jest.fn(() => Promise.resolve()),
removeItem: jest.fn(() => Promise.resolve()),
clear: jest.fn(() => Promise.resolve()),
getAllKeys: jest.fn(() => Promise.resolve([])),
multiGet: jest.fn(() => Promise.resolve([])),
multiSet: jest.fn(() => Promise.resolve()),
multiRemove: jest.fn(() => Promise.resolve()),
};
global.window = global.window || {};
global.window.dispatchEvent = global.window.dispatchEvent || jest.fn();
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
jest.mock('react-native-config', () => ({
SUPABASE_URL: 'http://127.0.0.1:54321',
SUPABASE_ANON_KEY: 'test-anon-key',
}));
jest.mock('react-native-reanimated', () => {
const ReactNative = require('react-native');
const passthrough = value => value;
const animated = {
View: ReactNative.View,
Text: ReactNative.Text,
Image: ReactNative.Image,
ScrollView: ReactNative.ScrollView,
FlatList: ReactNative.FlatList,
SectionList: ReactNative.SectionList,
createAnimatedComponent: component => component,
// @gorhom/bottom-sheet registers its own UI props at import time.
addWhitelistedUIProps: jest.fn(),
addWhitelistedNativeProps: jest.fn(),
};
return {
__esModule: true,
default: animated,
Easing: {
ease: passthrough,
linear: passthrough,
out: passthrough,
inOut: passthrough,
bezier: () => passthrough,
},
// Reduce-motion is reported as off so animated components take their normal
// path under test; the reduced path is asserted separately where it matters.
useReducedMotion: () => false,
ReduceMotion: { System: 'system', Always: 'always', Never: 'never' },
useAnimatedStyle: updater => (typeof updater === 'function' ? updater() : {}),
useAnimatedProps: updater => (typeof updater === 'function' ? updater() : {}),
useAnimatedRef: () => ({ current: null }),
useAnimatedReaction: jest.fn(),
useAnimatedScrollHandler: () => jest.fn(),
useDerivedValue: updater => ({
value: typeof updater === 'function' ? updater() : updater,
}),
useSharedValue: value => ({ value }),
makeMutable: value => ({ value }),
cancelAnimation: jest.fn(),
measure: () => null,
scrollTo: jest.fn(),
runOnJS: fn => fn,
runOnUI: fn => fn,
interpolate: value => value,
interpolateColor: () => 'transparent',
Extrapolation: { CLAMP: 'clamp', EXTEND: 'extend', IDENTITY: 'identity' },
Extrapolate: { CLAMP: 'clamp', EXTEND: 'extend', IDENTITY: 'identity' },
withDelay: (_delay, value) => value,
withRepeat: value => value,
withSequence: (...values) => values[values.length - 1],
withSpring: value => value,
withTiming: value => value,
withDecay: value => value,
FadeIn: { duration: () => ({}) },
FadeOut: { duration: () => ({}) },
Layout: { duration: () => ({}) },
};
});
jest.mock('react-native-image-picker', () => ({
launchImageLibrary: jest.fn(),
}));
jest.mock('@maplibre/maplibre-react-native', () => {
const React = require('react');
const { View } = require('react-native');
const MapComponent = ({ children, ...props }) =>
React.createElement(View, props, children);
return {
Map: MapComponent,
Camera: React.forwardRef((_props, _ref) => null),
GeoJSONSource: MapComponent,
Layer: () => null,
};
});
jest.mock('react-native-geolocation-service', () => ({
requestAuthorization: jest.fn(() => Promise.resolve('granted')),
getCurrentPosition: jest.fn(),
watchPosition: jest.fn(() => 1),
clearWatch: jest.fn(),
stopObserving: jest.fn(),
}));
jest.mock('@react-native-firebase/app', () => ({
initializeApp: jest.fn(),
getApps: jest.fn(() => [{ name: '[DEFAULT]' }]),
}));
jest.mock('@sentry/react-native', () => ({
init: jest.fn(),
wrap: component => component,
captureException: jest.fn(),
captureMessage: jest.fn(),
}));
jest.mock('@react-native-firebase/auth', () => ({
getAuth: jest.fn(() => ({})),
signInWithPhoneNumber: jest.fn(),
signOut: jest.fn(),
}));
jest.mock('@react-native-firebase/messaging', () => ({
getMessaging: jest.fn(() => ({})),
requestPermission: jest.fn(() => Promise.resolve(1)),
getToken: jest.fn(() => Promise.resolve('mock-fcm-token')),
deleteToken: jest.fn(() => Promise.resolve()),
onTokenRefresh: jest.fn(() => jest.fn()),
onMessage: jest.fn(() => jest.fn()),
onNotificationOpenedApp: jest.fn(() => jest.fn()),
getInitialNotification: jest.fn(() => Promise.resolve(null)),
setBackgroundMessageHandler: jest.fn(),
AuthorizationStatus: {
NOT_DETERMINED: -1,
DENIED: 0,
AUTHORIZED: 1,
PROVISIONAL: 2,
},
}));