forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSetup.js
More file actions
96 lines (82 loc) · 2.09 KB
/
testSetup.js
File metadata and controls
96 lines (82 loc) · 2.09 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
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
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
jest.useFakeTimers();
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
jest.mock('@react-native-vector-icons/material-design-icons', () => {
const React = require('react');
const { Text } = require('react-native');
const MockIcon = ({ name, color, size, style, ...props }) => {
return (
<Text
style={[{ color, fontSize: size }, style]}
{...props}
>
{name || '□'}
</Text>
);
};
MockIcon.displayName = 'MockedMaterialDesignIcon';
return {
__esModule: true,
default: MockIcon,
};
});
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');
const timing = (value, config) => {
const animation = {
start: (callback) => {
setTimeout(() => {
value.setValue(config.toValue);
if (callback) {
callback({ finished: true });
}
}, 0);
},
value,
config,
stop: () => {
throw new Error('Not implemented');
},
reset: () => {
throw new Error('Not implemented');
},
};
return animation;
};
const loop = (animation) => {
return {
start: (callback) => {
setTimeout(() => {
if (callback) {
callback({ finished: true });
}
}, 0);
},
stop: () => {
throw new Error('Not implemented');
},
reset: () => {
throw new Error('Not implemented');
},
};
};
const parallel = (animations) => ({
start: (callback) => {
const results = animations.map((animation) => {
animation.start();
return { finished: true };
});
callback?.({ finished: results.every((result) => result.finished) });
},
});
RN.Animated.timing = timing;
RN.Animated.loop = loop;
RN.Animated.parallel = parallel;
return RN;
});
jest.mock('react-native/Libraries/Utilities/useWindowDimensions', () => ({
default: jest.fn().mockReturnValue({
fontScale: 1,
width: 750,
}),
}));