-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.setup.js
73 lines (64 loc) · 1.65 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
Object.setPrototypeOf(window, Window.prototype);
function getBorder(style) {
const { border, borderWidth, borderTopWidth, borderLeftWidth, borderRightWidth, borderBottomWidth } = style;
let bT = 0;
let bR = 0;
let bB = 0;
let bL = 0;
const bMatch = /(\d+)px/.exec(border || '');
if (bMatch) {
const w = Number(bMatch[1]);
bT = w;
bR = w;
bB = w;
bL = w;
}
if (borderWidth) {
const bw = borderWidth.split(' ');
bT = parseInt(bw[0]);
bR = bw[1] ? parseInt(bw[1]) : bT;
bB = bw[2] ? parseInt(bw[2]) : bT;
bL = bw[3] ? parseInt(bw[3]) : bR;
}
if (borderTopWidth) { bT = parseInt(borderTopWidth); }
if (borderLeftWidth) { bL = parseInt(borderLeftWidth); }
if (borderRightWidth) { bR = parseInt(borderRightWidth); }
if (borderBottomWidth) { bB = parseInt(borderBottomWidth); }
return { bT, bR, bB, bL };
}
Object.defineProperties(window.HTMLElement.prototype, {
// offsetLeft: {
// get() { return parseFloat(this.style.marginLeft) || 0; }
// },
// offsetTop: {
// get() { return parseFloat(this.style.marginTop) || 0; }
// },
offsetHeight: {
get() { return parseInt(this.style.height) || 0; }
},
offsetWidth: {
get() { return parseInt(this.style.width) || 0; }
},
clientHeight: {
get() {
const { bT, bB } = getBorder(this.style);
return this.offsetHeight - bT - bB;
}
},
clientWidth: {
get() {
const { bR, bL } = getBorder(this.style);
return this.offsetWidth - bR - bL;
}
},
scrollHeight: {
get() {
return this.clientHeight + 50;
}
},
scrollWidth: {
get() {
return this.clientWidth + 50;
}
}
});