-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.setup.js
66 lines (60 loc) · 1.97 KB
/
jest.setup.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
import {jest} from '@jest/globals';
import React from 'react';
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
jest.mock('react-native-safari-view', () => ({
show: () => {},
}));
jest.mock('react-native-permissions', () =>
require('react-native-permissions/mock'),
);
jest.mock('react-native-qrcode-scanner', () => {});
React.NativeModules = {};
React.NativeModules.RNBranchEventEmitter = {};
React.NativeModules.RNBranch = {};
const NativeModules = {
RNFirebase: {
apps: [{name: '[DEFAULT]'}, {name: 'notifications'}, {name: 'messaging'}],
},
RNFirebaseAnalytics: {
setUserId: jest.fn(),
},
RNFirebaseMessaging: {
jsInitialised: jest.fn(() => Promise.resolve()),
getToken: jest.fn(() => Promise.resolve('FIREBASE_TOKEN')),
},
RNFirebaseNotifications: {
jsInitialised: jest.fn(() => Promise.resolve()),
getInitialNotification: jest.fn(() => Promise.resolve()),
},
RNFSManager: {
RNFSMainBundlePath: 'main-bundle',
RNFSCachesDirectoryPath: 'caches',
RNFSDocumentDirectoryPath: 'documents',
RNFSExternalDirectoryPath: 'external',
RNFSExternalStorageDirectoryPath: 'external-storage',
RNFSTemporaryDirectoryPath: 'tmp',
RNFSLibraryDirectoryPath: 'library',
RNFSFileTypeRegular: 'file-type-regular',
RNFSFileTypeDirectory: 'file-type-directory',
},
RNShare: {},
OurLocation: {
getLocation: jest
.fn()
.mockResolvedValue({coords: {latitude: 55, longitude: 37}}),
requestAuthorization: jest.fn(() => Promise.resolve()),
},
OurNavigator: {
present: jest.fn(() => Promise.resolve()),
dismiss: jest.fn(() => Promise.resolve()),
push: jest.fn(() => Promise.resolve()),
pop: jest.fn(() => Promise.resolve()),
},
};
Object.keys(NativeModules).forEach(name => {
mockReactNativeModule(name, NativeModules[name]);
});
function mockReactNativeModule(name, shape) {
jest.doMock(name, () => shape, {virtual: true});
require('react-native').NativeModules[name] = shape;
}