-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
63 lines (50 loc) · 1.13 KB
/
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
import "jest-canvas-mock";
import React from "react";
global.React = React;
jest.mock("react", () => ({
...jest.requireActual("react"),
useLayoutEffect: jest.requireActual("react").useEffect,
}));
jest.setTimeout(60000);
Object.defineProperty(window, "open", {
value: jest.fn,
});
global.requestAnimationFrame =
global.requestAnimationFrame ||
function requestAnimationFrame(cb) {
return setTimeout(cb, 0);
};
global.cancelAnimationFrame =
global.cancelAnimationFrame ||
function cancelAnimationFrame() {
return null;
};
// browserMocks.js
export const localStorageMock = (() => {
let store = {
locale: "zh",
};
return {
getItem(key) {
return store[key] || null;
},
setItem(key, value) {
store[key] = value.toString();
},
removeItem(key) {
store[key] = null;
},
clear() {
store = {};
},
};
})();
Object.defineProperty(window, "localStorage", {
value: localStorageMock,
writable: true,
});
Object.defineProperty(window, "cancelAnimationFrame", {
value: () => null,
});
Math.random = () => 0.8404419276253765;
global.URL.createObjectURL = () => {};