forked from pankod/react-native-picker-modal-view
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupTests.ts
40 lines (32 loc) · 959 Bytes
/
setupTests.ts
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
// JSDOM
export interface Global {
document: Document;
window: Window;
navigator: {
userAgent: string
}
}
declare var global: Global;
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;
function copyProps(src, target) {
const props: any = Object.getOwnPropertyNames(src)
.filter((prop) => typeof target[prop] === 'undefined')
.map((prop) => Object.getOwnPropertyDescriptor(src, prop));
Object.defineProperties(target, props);
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: "node.js",
};
copyProps(window, global);
// JSDOM done
// Mock and Enzyme
jest.mock('react-native', () => require('react-native-mock-render'), { virtual: true })
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
Enzyme.configure({ adapter: new Adapter() });
// Mock and Enzyme done
jest.useFakeTimers()