-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.js
89 lines (81 loc) · 1.99 KB
/
jest.setup.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import "./polyfills";
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import createGoogleMapsMock from "jest-google-maps-mock";
import MockDate from "mockdate";
import "./polyfills";
Enzyme.configure({ adapter: new Adapter() });
MockDate.set("2018-01-01T00:00:00", -780);
Object.defineProperties(global, {
API_URL: { value: "http://localhost/api", writable: true },
});
delete window.location;
window.location = {
assign: jest.fn(),
hash: "",
host: "localhost",
hostname: "localhost",
href: "http://localhost",
origin: "http://localhost",
pathname: "",
port: 80,
protocol: "http:",
reload: jest.fn(),
search: "",
};
Object.defineProperties(window, {
dataLayer: {
value: [],
writable: true,
},
google: {
value: {
maps: createGoogleMapsMock(),
},
writable: true,
},
requestAnimationFrame: {
value: (callback) => setTimeout(callback, 0),
writable: true,
},
scrollTo: {
value: jest.fn(),
writable: true,
},
});
Object.defineProperty(navigator, "language", {
value: "en-NZ",
});
const serviceWorkerEvents = {};
Object.defineProperty(window.navigator, "serviceWorker", {
value: {
addEventListener: jest.fn((event, handler) => {
if (!serviceWorkerEvents[event]) {
serviceWorkerEvents[event] = [];
}
serviceWorkerEvents[event].push(handler);
}),
controller: {
postMessage: jest.fn(),
state: "activated",
},
dispatchEvent: jest.fn((event) => {
if (serviceWorkerEvents[event.type]) {
serviceWorkerEvents[event.type].forEach((handler) => {
handler(event);
});
}
}),
register: jest.fn(),
removeEventListener: jest.fn((event, handler) => {
if (serviceWorkerEvents[event]) {
serviceWorkerEvents[event].forEach((boundHandler, index) => {
if (handler === boundHandler) {
serviceWorkerEvents[event].splice(index, 1);
}
});
}
}),
},
writable: true,
});