-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.js
80 lines (68 loc) · 2.4 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
import '@testing-library/jest-native/extend-expect'
import {jest} from '@jest/globals'
import AbortController from 'abort-controller'
import fetch, {Headers, Request, Response} from 'node-fetch'
import 'react-native-gesture-handler/jestSetup'
import {server} from './src/test/mocks/server'
jest.useFakeTimers()
jest.mock('react-native-gesture-handler', () => {
const View = require('react-native/Libraries/Components/View/View')
return {
Swipeable: View,
DrawerLayout: View,
State: {},
ScrollView: View,
Slider: View,
Switch: View,
TextInput: View,
ToolbarAndroid: View,
ViewPagerAndroid: View,
DrawerLayoutAndroid: View,
WebView: View,
NativeViewGestureHandler: View,
TapGestureHandler: View,
FlingGestureHandler: View,
ForceTouchGestureHandler: View,
LongPressGestureHandler: View,
PanGestureHandler: View,
PinchGestureHandler: View,
RotationGestureHandler: View,
/* Buttons */
RawButton: View,
BaseButton: View,
RectButton: View,
BorderlessButton: View,
/* Other */
FlatList: View,
gestureHandlerRootHOC: () => null,
Directions: {},
}
})
// surpressing warning resulted by useLinking due to usage of NavigationContainer
jest.mock('@react-navigation/native/lib/commonjs/useLinking.native', () => ({
default: () => ({getInitialState: {then: () => null}}),
__esModule: true,
}))
// surpressing Animated: `useNativeDriver` is not supported warning
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')
// jest.mock('react-native-reanimated', () => {
// const Reanimated = require('react-native-reanimated/mock')
// // The mock for `call` immediately calls the callback which is incorrect
// // So we override it with a no-op
// Reanimated.default.call = () => {}
// return Reanimated
// })
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')
global.fetch = fetch
global.Headers = Headers
global.Request = Request
global.Response = Response
global.AbortController = AbortController
// Establish API mocking before all tests.
beforeAll(() => server.listen())
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => server.close())