-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest_setup.ts
38 lines (31 loc) · 1.24 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
import { cleanup } from 'react-native-testing-library'
// @ts-ignore
const svgMock = require('react-native-svg-mock')
jest.useFakeTimers()
if (typeof window !== 'object') {
// @ts-ignore
global.window = global
// @ts-ignore
global.window.navigator = {}
}
// @ts-ignore
global.fetch = require('jest-fetch-mock')
// Makes sure components are unmounted after each test
// TODO: remove once https://github.com/callstack/react-native-testing-library/pull/238 is merged and we upgrade
afterEach(cleanup)
// 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/src/components/AnimatedView.js', () => 'View')
jest.mock(
'react-native/Libraries/Animated/src/components/AnimatedScrollView.js',
() => 'RCTScrollView'
)
// 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(),
}))