forked from valora-inc/wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest_setup.ts
108 lines (96 loc) · 3.08 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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(),
}))
// Mock Pixel Ratio to always return 1
jest.mock('react-native/Libraries/Utilities/PixelRatio.js', () => ({
roundToNearestPixel: jest.fn(() => 1),
getPixelSizeForLayoutSize: jest.fn(() => 1),
getFontScale: jest.fn(() => 1),
}))
jest.mock('react-native-shake', () => ({
addListener: jest.fn(),
removeAllListeners: jest.fn(),
}))
jest.mock('@supabase/supabase-js', () => {
return {
createClient: jest.fn().mockImplementation(() => {
return {
from: jest.fn().mockReturnThis(),
select: jest.fn().mockImplementation(() => ({
eq: jest.fn().mockReturnThis(),
in: jest.fn().mockReturnThis(),
is: jest.fn().mockReturnThis(),
order: jest.fn().mockReturnThis(),
gte: jest.fn().mockReturnThis(),
lte: jest.fn().mockReturnThis(),
data: [
{
id: 'mockedRoleId',
org_users: [{ id: 'mockUserId', status: 'active' }],
},
],
error: null,
})),
update: jest.fn().mockImplementation(() => ({
eq: jest.fn().mockReturnThis(),
in: jest.fn().mockReturnThis(),
is: jest.fn().mockReturnThis(),
order: jest.fn().mockReturnThis(),
gte: jest.fn().mockReturnThis(),
lte: jest.fn().mockReturnThis(),
select: jest.fn().mockReturnThis(),
data: [
{
id: 'mockedRoleId',
org_users: [{ id: 'mockUserId', status: 'active' }],
},
],
error: null,
})),
}
}),
}
})
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'))
// @ts-ignore
global.__reanimatedWorkletInit = jest.fn()