-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest-setup.ts
73 lines (64 loc) · 2.29 KB
/
jest-setup.ts
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
// Import Jest Native matchers
import '@testing-library/jest-native/extend-expect';
import { useAppSelector } from './src/lib/redux/Hooks';
import { ThemeState } from './src/lib/redux/slices/ThemeSlice';
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('react-native-vector-icons/FontAwesome5', () => 'FontAwesome5');
jest.mock('react-native-webview', () => 'WebView');
jest.mock('@react-native-async-storage/async-storage', () =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
require('@react-native-async-storage/async-storage/jest/async-storage-mock'),
);
jest.mock('@expo-google-fonts/inter', () => ({
useFonts: () => [true, null],
Inter_500Medium: {},
}));
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
jest.mock('@react-navigation/native', () => ({
...jest.requireActual('@react-navigation/native'),
useNavigation: () => ({
navigate: jest.fn(),
}),
}));
jest.mock('react-redux', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const ActualReactRedux = jest.requireActual('react-redux');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return {
...ActualReactRedux,
useSelector: jest.fn().mockImplementation(() => {
return {};
}),
};
});
jest.mock('./src/lib/redux/Hooks', () => ({
useAppSelector: jest.fn(),
useAppDispatch: jest.fn(),
}));
const mockedState: ThemeState = {
theme: 'light',
isHighContrastEnabled: false,
};
(useAppSelector as jest.Mock).mockReturnValue(mockedState);
jest.mock('react-i18next', () => ({
// this mock makes sure any components using the translation hook can use it
// without a warning being shown
useTranslation: () => {
return {
t: (str: unknown) => str,
i18n: {
// eslint-disable-next-line @typescript-eslint/no-empty-function
changeLanguage: () => new Promise(() => {}),
},
};
},
}));
jest.mock('expo-haptics', () => ({
impactAsync: jest.fn(),
ImpactFeedbackStyle: {
Light: 'light',
Medium: 'medium',
Heavy: 'heavy',
},
}));