-
Notifications
You must be signed in to change notification settings - Fork 1
/
unitTestSetup.ts
39 lines (34 loc) · 901 Bytes
/
unitTestSetup.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
import { JSDOM } from "jsdom";
interface Global extends NodeJS.Global {
window: Window;
document: Document;
navigator: {
userAgent: string;
};
}
const globalNode: Global = {
window: window,
document: window.document,
navigator: {
userAgent: "node.js"
},
...global
};
// Simulate window for Node.js
if (!globalNode.window && !globalNode.document) {
const { window } = new JSDOM("<!doctype html><html><body></body></html>", {
beforeParse(win) {
win.scrollTo = () => {};
},
pretendToBeVisual: false,
userAgent: "mocha"
});
// Configure global variables which like to be used in testing
globalNode.window = window;
globalNode.document = window.document;
globalNode.navigator = window.navigator;
}
import * as enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
const adapter = new Adapter();
enzyme.configure({ adapter });