forked from bamlab/react-native-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
50 lines (46 loc) · 1.25 KB
/
jest.setup.ts
File metadata and controls
50 lines (46 loc) · 1.25 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
import '@testing-library/jest-native/extend-expect';
/**
* Suppress React 16.8 act() warnings globally.
* Waiting for react-native to support react 16.9
*/
const originalConsoleError = console.error;
console.error = (...args) => {
if (/Warning.*not wrapped in act/.test(args[0])) {
return;
}
originalConsoleError.call(console, ...args);
};
/**
* Override console.warn to hide unwanted warnings
*/
const originalConsoleWarn = console.warn;
console.warn = (...args) => {
const warningMessage = args[0];
const warningsToHide = [
'Calling .measureInWindow()',
'Calling .measureLayout()',
'Calling .setNativeProps()',
'Calling .focus()',
'Calling .blur()',
];
const shouldPrintWarning = warningsToHide.reduce(
(shouldPrintWarning, warningToHide) =>
shouldPrintWarning && !warningMessage.includes(warningToHide),
true
);
if (shouldPrintWarning) {
originalConsoleWarn(...args);
}
};
/**
* Mock react-native-gesture-handler to render react navigation components and their animations
*/
jest.mock('react-native-gesture-handler', () => {
const View = require('react-native/Libraries/Components/View/View');
return {
State: {},
PanGestureHandler: View,
BaseButton: View,
Directions: {},
};
});