-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
159 lines (142 loc) · 4.89 KB
/
Copy pathjest.setup.js
File metadata and controls
159 lines (142 loc) · 4.89 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import 'react-native-gesture-handler/jestSetup';
// Mock Expo Crypto
jest.mock('expo-crypto', () => ({
getRandomBytes: jest.fn((length) => new Uint8Array(length).fill(0)), // Mocked random bytes
}));
// Mock Expo SecureStore
jest.mock('expo-secure-store', () => ({
setItemAsync: jest.fn(() => Promise.resolve()),
getItemAsync: jest.fn(() => Promise.resolve(null)),
deleteItemAsync: jest.fn(() => Promise.resolve()),
}));
// Mock Expo LocalAuthentication
jest.mock('expo-local-authentication', () => ({
hasHardwareAsync: jest.fn(() => Promise.resolve(true)),
isEnrolledAsync: jest.fn(() => Promise.resolve(true)),
authenticateAsync: jest.fn(() => Promise.resolve({ success: true })),
}));
// Mock Expo Localization
jest.mock('expo-localization', () => ({
locale: 'it-IT',
locales: ['it-IT'],
getLocales: () => [{ languageCode: 'it', regionCode: 'IT', languageTag: 'it-IT' }],
}));
// Mock Expo NavigationBar
jest.mock('expo-navigation-bar', () => ({
__esModule: true,
NavigationBar: jest.fn(() => null),
}));
// Mock Expo FileSystem
jest.mock('expo-file-system', () => ({
File: class MockFile {
constructor(...parts) {
this.uri = parts
.map((part) => (typeof part === 'string' ? part : part.uri))
.reduce((path, part) => `${path.replace(/\/$/, '')}/${part.replace(/^\//, '')}`);
this.exists = true;
this.extension = this.uri.match(/\.[a-z0-9]+$/i)?.[0] ?? '';
}
copy() {
return Promise.resolve();
}
},
Paths: { document: { uri: 'file:///test-directory' } },
documentDirectory: 'file:///test-directory/',
writeAsStringAsync: jest.fn(() => Promise.resolve()),
readAsStringAsync: jest.fn(() => Promise.resolve('')),
deleteAsync: jest.fn(() => Promise.resolve()),
getInfoAsync: jest.fn(() => Promise.resolve({ exists: true })),
makeDirectoryAsync: jest.fn(() => Promise.resolve()),
}));
// Mock Expo Constants
jest.mock('expo-constants', () => ({
manifest: {
extra: {},
},
}));
// Mock Expo Font
jest.mock('expo-font', () => ({
loadAsync: jest.fn(() => Promise.resolve()),
isLoaded: jest.fn(() => true),
}));
// Mock Expo Notifications
jest.mock('expo-notifications', () => ({
AndroidImportance: { DEFAULT: 3 },
setNotificationHandler: jest.fn(),
setNotificationChannelAsync: jest.fn().mockResolvedValue(undefined),
cancelAllScheduledNotificationsAsync: jest.fn().mockResolvedValue(undefined),
cancelScheduledNotificationAsync: jest.fn().mockResolvedValue(undefined),
getAllScheduledNotificationsAsync: jest.fn().mockResolvedValue([]),
getPermissionsAsync: jest.fn().mockResolvedValue({ status: 'granted' }),
requestPermissionsAsync: jest.fn().mockResolvedValue({ status: 'granted' }),
scheduleNotificationAsync: jest.fn().mockResolvedValue('notification-id'),
addNotificationReceivedListener: jest.fn(() => ({ remove: jest.fn() })),
addNotificationResponseReceivedListener: jest.fn(() => ({ remove: jest.fn() })),
}));
// Mock Argon2 for tests (avoid native dependency warnings)
jest.mock('react-native-argon2', () => ({
argon2: jest.fn(async (password, salt, options) => ({
rawHash: `argon2-${password}-${salt}-${options?.iterations ?? 0}-${options?.memory ?? 0}`,
})),
}));
// Mock React Native Reanimated
jest.mock('react-native-reanimated', () => {
const React = require('react');
const { View } = require('react-native');
const enteringBuilder = {
duration: jest.fn(() => enteringBuilder),
delay: jest.fn(() => enteringBuilder),
};
const AnimatedView = ({ entering: _entering, exiting: _exiting, ...props }) =>
React.createElement(View, props);
return {
__esModule: true,
default: { View: AnimatedView },
FadeIn: enteringBuilder,
FadeInDown: enteringBuilder,
FadeInUp: enteringBuilder,
FadeOutUp: enteringBuilder,
};
});
// Mock Safe Area Context
jest.mock('react-native-safe-area-context', () => {
const inset = { top: 0, right: 0, bottom: 0, left: 0 };
return {
SafeAreaProvider: jest.fn(({ children }) => children),
SafeAreaView: jest.fn(({ children }) => children),
useSafeAreaInsets: jest.fn(() => inset),
};
});
// Mock Navigation
const mockNavigate = jest.fn();
const mockGoBack = jest.fn();
const mockSetOptions = jest.fn();
const mockNavigation = {
navigate: mockNavigate,
goBack: mockGoBack,
setOptions: mockSetOptions,
addListener: jest.fn(),
removeListener: jest.fn(),
dispatch: jest.fn(),
canGoBack: jest.fn(),
isFocused: jest.fn().mockReturnValue(true),
};
jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
...actualNav,
useNavigation: () => mockNavigation,
useRoute: () => ({
params: {},
}),
useIsFocused: () => true,
};
});
// Silence warnings
const originalConsoleError = console.error;
console.error = (...args) => {
if (typeof args[0] === 'string' && args[0].includes('not wrapped in act')) {
return;
}
originalConsoleError(...args);
};