-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
124 lines (112 loc) · 3.09 KB
/
Copy pathjest.setup.js
File metadata and controls
124 lines (112 loc) · 3.09 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
/**
* Jest Setup
*
* Global test configuration and mocks for React Native testing.
*/
import '@testing-library/jest-native/extend-expect';
// Mock AsyncStorage
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);
// Mock NetInfo
jest.mock('@react-native-community/netinfo', () => ({
addEventListener: jest.fn(() => jest.fn()),
fetch: jest.fn(() => Promise.resolve({
isConnected: true,
isInternetReachable: true,
})),
}));
// Mock expo-constants
jest.mock('expo-constants', () => ({
expoConfig: {
extra: {
supabaseUrl: 'https://test.supabase.co',
supabaseAnonKey: 'test-anon-key',
environment: 'test',
},
},
}));
// Mock expo-font
jest.mock('expo-font', () => ({
useFonts: () => [true, null],
loadAsync: jest.fn(),
}));
// Mock expo-splash-screen
jest.mock('expo-splash-screen', () => ({
preventAutoHideAsync: jest.fn(),
hideAsync: jest.fn(),
}));
// Mock react-native-reanimated
jest.mock('react-native-reanimated', () => {
const Reanimated = require('react-native-reanimated/mock');
Reanimated.default.call = () => {};
return Reanimated;
});
// Mock react-native-safe-area-context
jest.mock('react-native-safe-area-context', () => {
const inset = { top: 0, right: 0, bottom: 0, left: 0 };
return {
SafeAreaProvider: ({ children }) => children,
SafeAreaView: ({ children }) => children,
useSafeAreaInsets: () => inset,
};
});
// Mock react-native-gesture-handler
jest.mock('react-native-gesture-handler', () => {
const View = require('react-native').View;
return {
GestureHandlerRootView: View,
Swipeable: View,
DrawerLayout: View,
State: {},
ScrollView: View,
Slider: View,
Switch: View,
TextInput: View,
ToolbarAndroid: View,
TouchableHighlight: View,
TouchableNativeFeedback: View,
TouchableOpacity: View,
TouchableWithoutFeedback: View,
FlatList: View,
gestureHandlerRootHOC: jest.fn(),
NativeViewGestureHandler: View,
Directions: {},
};
});
// Mock Supabase
jest.mock('@supabase/supabase-js', () => ({
createClient: jest.fn(() => ({
auth: {
getSession: jest.fn(() => Promise.resolve({ data: { session: null }, error: null })),
onAuthStateChange: jest.fn(() => ({ data: { subscription: { unsubscribe: jest.fn() } } })),
signInWithPassword: jest.fn(),
signUp: jest.fn(),
signOut: jest.fn(),
resetPasswordForEmail: jest.fn(),
getUser: jest.fn(),
},
from: jest.fn(() => ({
select: jest.fn(() => ({
eq: jest.fn(() => ({
single: jest.fn(() => Promise.resolve({ data: null, error: null })),
})),
})),
})),
})),
}));
// Silence console warnings in tests
const originalWarn = console.warn;
console.warn = (...args) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('componentWillReceiveProps') ||
args[0].includes('componentWillMount') ||
args[0].includes('Animated'))
) {
return;
}
originalWarn.call(console, ...args);
};
// Global test timeout
jest.setTimeout(10000);