-
Notifications
You must be signed in to change notification settings - Fork 44
/
jest-setup.js
99 lines (91 loc) · 2.44 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
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
/* eslint-disable no-undef */
import {NativeModules} from 'react-native';
jest.mock('react-native-permissions', () =>
require('react-native-permissions/mock'),
);
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
jest.mock('react-native-device-info', () =>
require('react-native-device-info/jest/react-native-device-info-mock'),
);
jest.mock('@react-native-clipboard/clipboard', () =>
require('@react-native-clipboard/clipboard/jest/clipboard-mock'),
);
process.env.NODE_ENV = 'test';
// Workaround for https://github.com/react-native-webview/react-native-webview/issues/2934
jest.mock('react-native/Libraries/TurboModule/TurboModuleRegistry', () => {
const turboModuleRegistry = jest.requireActual(
'react-native/Libraries/TurboModule/TurboModuleRegistry',
);
return {
...turboModuleRegistry,
getEnforcing: (name) => {
if (name === 'RNCWebView') {
return null;
}
return turboModuleRegistry.getEnforcing(name);
},
};
});
NativeModules.RNDateTimePickerManager = {};
NativeModules.RNDateTimePickerManager.getDefaultDisplayValue = jest.fn(() =>
Promise.resolve({
determinedDisplayValue: 'spinner',
}),
);
NativeModules.TextToSpeech = {};
NativeModules.TextToSpeech.voices = jest.fn(() =>
Promise.resolve({
voices: [],
}),
);
jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
...actualNav,
useNavigation: () => ({
navigate: jest.fn(),
dispatch: jest.fn(),
}),
useNavigationState: jest.fn(),
useIsFocused: () => {
return true;
},
};
});
// For NetworkExamplePage.tsx
global.fetch = jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({
title: 'The Basics - Networking',
description: 'Your app fetched this from a remote endpoint!',
movies: [
{
id: '1',
title: 'Star Wars',
releaseYear: '1977',
},
{
id: '2',
title: 'Back to the Future',
releaseYear: '1985',
},
{
id: '3',
title: 'The Matrix',
releaseYear: '1999',
},
{
id: '4',
title: 'Inception',
releaseYear: '2010',
},
{
id: '5',
title: 'Interstellar',
releaseYear: '2014',
},
],
}),
}),
);