-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjestMockSetup.js
106 lines (91 loc) · 3.55 KB
/
jestMockSetup.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { jest } from '@jest/globals'; // eslint-disable-line import/no-extraneous-dependencies
import 'react-native-gesture-handler/jestSetup';
jest.mock('@react-navigation/stack');
// This mock is specially important because some libs still didn't updated
// the way to call NativeEventEmitter after a refactoring in react-native.
// Therefore, without it, test may complain with the following message:
// > Invariant Violation: new NativeEventEmitter() requires a non-null argument.
//
// See the react-native PR that introduce this problem:
// https://github.com/facebook/react-native/commit/114be1d2170bae2d29da749c07b45acf931e51e2
//
// The package that calls in ole fashion the NativeEventEmitter
// is the react-native-device-info.
//
// See the issue describing the problem and the solution:
// https://github.com/react-native-device-info/react-native-device-info/issues/1507
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
// react-native-device-info
// const RNDeviceInfo = {};
// jest.mock('react-native-device-info', () => ({
// default: {
// NativeModule: ({
// default: RNDeviceInfo
// })
// }
// }));
jest.mock('react-native-device-info', () => jest.requireActual('react-native-device-info/jest/react-native-device-info-mock'));
// jest-babel transformer ignores the node_module. Threfore,
// we should either mock the module or configure to add it
// in the transformation.
// See the issue discussion: https://github.com/oblador/react-native-keychain/issues/72#issuecomment-309809798
//
// A more elegant solution would be the react-native-keychain team
// provide a jest setup file. We may contribute with them creating one.
jest.mock('react-native-keychain');
// react-native-gesture-handler faces the same problem of
// react-native-keychain. However, the team provides a setupFile
// which we can use in the "setupFiles" configuration withing
// jest in package.json.
//
// Don't remove this comment, because this is a documentation
// to increase awareness about these corner cases.
//
// See the jestSetup.js file from the project:
// https://github.com/software-mansion/react-native-gesture-handler/blob/main/jestSetup.js
//
// This solution was elaboreated by many contributors in this issue:
// https://github.com/software-mansion/react-native-gesture-handler/issues/344
jest.mock('@notifee/react-native', () => jest.requireActual('@notifee/react-native/jest-mock'));
jest.mock('react-native-status-bar-height');
jest.mock('@react-native-async-storage/async-storage', () => jest.requireActual('@react-native-async-storage/async-storage/jest/async-storage-mock'));
jest.mock('@react-native-firebase/messaging');
jest.mock('@sentry/react-native');
jest.mock('react-native-version-number');
jest.mock('unleash-proxy-client', () => ({
UnleashClient: jest.fn(() => ({
getAllToggles: () => ({}),
isEnabled: () => false,
getVariant: () => ({}),
updateContext: () => {},
getContext: () => ({
appName: 'hathor-wallet-mobile',
environment: 'test',
userId: 'test-user',
sessionId: 'test-session',
remoteAddress: undefined,
properties: {},
}),
setContextField: () => {},
start: () => {},
stop: () => {},
on: () => {},
})),
EVENTS: {
INIT: 'INIT',
ERROR: 'ERROR',
READY: 'READY',
UPDATE: 'UPDATE',
IMPRESSION: 'IMPRESSION',
},
}));
const RNPermissionsModule = {};
jest.mock('react-native-permissions', () => ({
default: {
NativeModule: ({
default: RNPermissionsModule
})
}
}));
jest.mock('react-native-modal');
jest.mock('react-native-animatable');