Repository navigation
Expand file tree
/
Copy pathjest.setup.js
More file actions
65 lines (62 loc) · 1.85 KB
/
Copy pathjest.setup.js
File metadata and controls
65 lines (62 loc) · 1.85 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
// The suite only needs the public react-native entry. Loading the real package
// follows react-native/Libraries paths that move between releases, and React
// Native 0.88 throws when its removed InteractionManager export is read.
jest.mock('react-native', () => {
const React = require('react');
const hostComponents = new Map();
function createHostComponent(name) {
function Host(props) {
return React.createElement(name, props, props.children);
}
Host.displayName = name;
return Host;
}
return new Proxy(
{
PanResponder: {
create: jest.fn((config) => ({
panHandlers: {
onStartShouldSetResponder: config.onStartShouldSetPanResponder,
onMoveShouldSetResponder: config.onMoveShouldSetPanResponder,
},
})),
},
},
{
get(target, prop) {
if (prop === '__esModule') {
return true;
}
if (Object.prototype.hasOwnProperty.call(target, prop)) {
return target[prop];
}
if (typeof prop !== 'string') {
return undefined;
}
if (!hostComponents.has(prop)) {
hostComponents.set(prop, createHostComponent(prop));
}
return hostComponents.get(prop);
},
}
);
});
// Silence console logs during tests unless debugging.
// React 19 prints this from react-test-renderer, which the testing library still uses.
const reactTestRendererDeprecation = 'react-test-renderer is deprecated';
if (process.env.DEBUG !== 'true') {
const originalError = console.error;
global.console = {
...console,
log: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: (...args) => {
if (typeof args[0] === 'string' && args[0].includes(reactTestRendererDeprecation)) {
return;
}
originalError(...args);
},
};
}