-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.setup.js
62 lines (53 loc) · 1.54 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
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage)
const mockedNavigate = jest.fn()
jest.mock('@react-navigation/native', () => {
return {
...jest.requireActual('@react-navigation/native'),
useNavigation: () => ({
navigate: mockedNavigate,
}),
}
})
jest.mock('redux-persist', () => {
const real = jest.requireActual('redux-persist')
return {
...real,
persistReducer: jest
.fn()
.mockImplementation((config, reducers) => reducers),
}
})
jest.mock('react-native-get-random-values', () => ({
getRandomBase64: jest.fn(),
}))
const mockDispatch = jest.fn()
jest.mock('react-redux', () => ({
useSelector: jest.fn(),
useDispatch: () => mockDispatch,
}))
// Mock any Native Modules
const NativeModules = {
AudioSensor: {
getCurrentVolume: jest.fn(),
isHeadphonesConnected: jest.fn(),
addVolumeListener: jest.fn(),
addHeadphonesListener: jest.fn(),
},
}
Object.keys(NativeModules).forEach((name) => {
const shape = NativeModules[name]
jest.doMock(name, () => shape, { virtual: true })
require('react-native').NativeModules[name] = shape
})
jest.mock('@react-native-community/push-notification-ios', () => {
return {
addEventListener: jest.fn(),
requestPermissions: jest.fn(() => Promise.resolve()),
getInitialNotification: jest.fn(() => Promise.resolve()),
}
})
jest.mock('react-airplay', () => ({
showRoutePicker: jest.fn(),
AirplayButton: jest.fn(),
}))