-
Notifications
You must be signed in to change notification settings - Fork 87
/
jest_setup.ts
57 lines (48 loc) · 1.57 KB
/
jest_setup.ts
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
import '@testing-library/jest-native/extend-expect'
import 'react-native-svg-mock'
beforeAll(() => {
jest.useFakeTimers()
})
if (typeof window !== 'object') {
// @ts-ignore
global.window = global
// @ts-ignore
global.window.navigator = {}
}
// @ts-ignore
global.fetch = require('jest-fetch-mock')
// Mock LayoutAnimation as it's done not automatically
jest.mock('react-native/Libraries/LayoutAnimation/LayoutAnimation.js')
// Mock Animated Views this way otherwise we get a
// `JavaScript heap out of memory` error when a ref is set (?!)
// See https://github.com/callstack/react-native-testing-library/issues/539
jest.mock('react-native/Libraries/Animated/components/AnimatedView.js', () => ({
default: 'View',
}))
jest.mock('react-native/Libraries/Animated/components/AnimatedScrollView.js', () => ({
default: 'RCTScrollView',
}))
jest.mock('react-native-webview', () => {
const { View } = require('react-native')
return {
default: View,
WebView: View,
}
})
// Mock ToastAndroid as it's not done automatically
jest.mock('react-native/Libraries/Components/ToastAndroid/ToastAndroid.android.js', () => ({
show: jest.fn(),
showWithGravity: jest.fn(),
showWithGravityAndOffset: jest.fn(),
}))
jest.mock('react-native-shake', () => ({
addListener: jest.fn(),
removeAllListeners: jest.fn(),
}))
jest.mock('@react-native-clipboard/clipboard', () => ({
setString: jest.fn(),
getString: jest.fn(),
hasString: jest.fn(),
}))
// this mock defaults to granting all permissions
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))