-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathjest.setup-before-env.js
More file actions
56 lines (52 loc) · 1.4 KB
/
jest.setup-before-env.js
File metadata and controls
56 lines (52 loc) · 1.4 KB
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
// This file runs before Jest environment is set up
// Mock React Native components globally before any imports
// Set NODE_ENV early
process.env.NODE_ENV = 'test';
// Mock React Native entirely
jest.doMock('react-native', () => {
const React = require('react');
// Create mock components that work with React Native Testing Library
const mockComponent = (name) => {
const Component = React.forwardRef((props, ref) => {
return React.createElement(name, { ...props, ref });
});
Component.displayName = name;
return Component;
};
return {
Platform: {
OS: 'ios',
select: jest.fn(options => options.ios),
},
Dimensions: {
get: jest.fn(() => ({ width: 375, height: 667 })),
},
View: mockComponent('View'),
Text: mockComponent('Text'),
Image: mockComponent('Image'),
TouchableOpacity: mockComponent('TouchableOpacity'),
ScrollView: mockComponent('ScrollView'),
StyleSheet: {
create: jest.fn(styles => styles),
},
Alert: {
alert: jest.fn(),
},
Animated: {
View: mockComponent('Animated.View'),
timing: jest.fn(() => ({
start: jest.fn(),
})),
Value: jest.fn(() => ({
setValue: jest.fn(),
addListener: jest.fn(),
removeListener: jest.fn(),
})),
},
Easing: {
linear: jest.fn(),
ease: jest.fn(),
quad: jest.fn(),
},
};
});