-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSetup.ts
More file actions
92 lines (82 loc) · 2.44 KB
/
testSetup.ts
File metadata and controls
92 lines (82 loc) · 2.44 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
/**
* Defines the React 16 Adapter for Enzyme.
*
* @link http://airbnb.io/enzyme/docs/installation/#working-with-react-16
* @copyright 2017 Airbnb, Inc.
*/
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { NativeModules } from 'react-native'
import { deactivateLogging } from './src/utils/Logger'
jest.useFakeTimers()
configure({ adapter: new Adapter() })
deactivateLogging()
const items = {} as any
jest.mock('@react-native-community/async-storage', () => ({
AsyncStorage: {
getItem: jest.fn(item => Promise.resolve(items[item])),
removeItem: jest.fn(item => Promise.resolve(delete items[item])),
setItem: jest.fn((item, value) => {
return new Promise((resolve, reject) => {
items[item] = value
resolve(value)
})
}),
},
}))
// Add navigator.geolocation to global object so importing
// react-native-geolocation-service doesn't cause jest to die
const globalAny: any = global
globalAny.navigator = {}
globalAny.navigator.geolocation = {}
/* https://github.com/expo/expo/blob/f882ffbc52ba910ecacefe264081e7eeb77c9665/packages/jest-expo/src/setup.js#L167-L199 */
jest.mock('react-native-gesture-handler', () => {
const View = require('react-native/Libraries/Components/View/View')
return {
DrawerLayout: View,
DrawerLayoutAndroid: View,
FlingGestureHandler: View,
ForceTouchGestureHandler: View,
LongPressGestureHandler: View,
NativeViewGestureHandler: View,
PanGestureHandler: View,
PinchGestureHandler: View,
RotationGestureHandler: View,
ScrollView: View,
Slider: View,
State: {},
Swipeable: View,
Switch: View,
TapGestureHandler: View,
TextInput: View,
ToolbarAndroid: View,
ViewPagerAndroid: View,
WebView: View,
/* Buttons */
BaseButton: View,
BorderlessButton: View,
RawButton: View,
RectButton: View,
/* Other */
Directions: {},
FlatList: View,
gestureHandlerRootHOC: jest.fn(),
}
})
// https://github.com/react-native-community/react-native-device-info#troubleshooting
jest.mock('react-native-device-info', () => {
return {
getApplicationName: jest.fn(),
getBuildNumber: jest.fn(),
getDeviceId: jest.fn(),
getReadableVersion: jest.fn(),
getSystemName: jest.fn(),
getSystemVersion: jest.fn(),
getTimezone: jest.fn(),
}
})
NativeModules.RNCNetInfo = {
addListener: jest.fn(),
getCurrentState: jest.fn(),
removeListeners: jest.fn()
};