-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathjest-setup.js
More file actions
60 lines (52 loc) · 1.52 KB
/
jest-setup.js
File metadata and controls
60 lines (52 loc) · 1.52 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
const RESET_MODULE_EXCEPTIONS = ['react', 'react-redux'];
const shonoActualRegistryCache = {};
RESET_MODULE_EXCEPTIONS.forEach((moduleName) => {
jest.doMock(
moduleName,
() => {
if (!shonoActualRegistryCache[moduleName]) {
shonoActualRegistryCache[moduleName] = jest.requireActual(moduleName);
}
return shonoActualRegistryCache[moduleName];
},
{ virtual: true }
);
});
const { mockDetox } = require('detox-testing-library-rnn-adapter');
jest.mock('react-native-gesture-handler', () => {
return {
gestureHandlerRootHOC: jest.fn(),
};
});
mockDetox(() => require('./playground/index'));
// detox-testing-library-rnn-adapter sets global.element to identity; real Detox chains .atIndex().
const origElement = global.element;
global.element = (matcher) => {
const el = origElement(matcher);
if (el == null || typeof el.atIndex === 'function') {
return el;
}
return new Proxy(el, {
get(target, prop, receiver) {
if (prop === 'atIndex') {
return function atIndex() {
return target;
};
}
return Reflect.get(target, prop, receiver);
},
});
};
beforeEach(() => {
const { mockNativeComponents } = require('react-native-navigation/Mock');
mockNativeComponents();
mockUILib();
});
setImmediate = (callback) => callback();
const mockUILib = () => {
const NativeModules = require('react-native').NativeModules;
NativeModules.KeyboardTrackingViewTempManager = {};
NativeModules.StatusBarManager = {
getHeight: () => 40,
};
};