-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
68 lines (64 loc) · 2.18 KB
/
jest.setup.js
File metadata and controls
68 lines (64 loc) · 2.18 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
// Jest setup file for react-native-lighthouse
// Stub native modules so React Native can load in Node (no native binary).
// Turbo modules must expose getConstants(); DeviceInfo/Dimensions expect window/screen metrics.
const stubNativeModule = () => ({
getConstants: jest.fn(() => ({
Dimensions: {
window: { width: 375, height: 812, scale: 2, fontScale: 1 },
screen: { width: 375, height: 812, scale: 2, fontScale: 1 },
},
})),
});
jest.mock('react-native/Libraries/TurboModule/TurboModuleRegistry', () => ({
getEnforcing: jest.fn(stubNativeModule),
get: jest.fn(() => null),
}));
// NativeEventEmitter requires a non-null native module on iOS; stub it for Node.
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter', () => {
return class NativeEventEmitter {
constructor() {}
addListener() {
return { remove: jest.fn() };
}
removeAllListeners() {}
};
});
// Mock react-native: use a Proxy so deprecated PropTypes are never read from RN (their getters log).
// We serve those from deprecated-react-native-prop-types and PanResponder from our mock.
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');
const DeprecatedPropTypes = require('deprecated-react-native-prop-types');
const panResponderMock = {
create: jest.fn((config) => ({
panHandlers: {
onStartShouldSetResponder: config.onStartShouldSetPanResponder,
onMoveShouldSetResponder: config.onMoveShouldSetPanResponder,
},
})),
};
const overrides = {
ColorPropType: DeprecatedPropTypes.ColorPropType,
EdgeInsetsPropType: DeprecatedPropTypes.EdgeInsetsPropType,
PointPropType: DeprecatedPropTypes.PointPropType,
ViewPropTypes: DeprecatedPropTypes.ViewPropTypes,
PanResponder: panResponderMock,
};
return new Proxy(RN, {
get(target, prop) {
if (Object.prototype.hasOwnProperty.call(overrides, prop)) {
return overrides[prop];
}
return target[prop];
},
});
});
// Silence console logs during tests unless debugging
if (process.env.DEBUG !== 'true') {
global.console = {
...console,
log: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
};
}