-
Notifications
You must be signed in to change notification settings - Fork 38
/
jest-setup.js
67 lines (64 loc) · 1.49 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
/* eslint-disable */
global.ResizeObserver = class ResizeObserver {
x;
constructor(cb) {
this.cb = cb;
}
observe() {
this.cb([{ borderBoxSize: { inlineSize: 0, blockSize: 0 } }]);
}
unobserve() {}
disconnect() {}
};
class DOMException extends Error {
constructor(message) {
super(message);
this.name = 'DOMException';
}
}
const abortSignal = () => {
return new DOMException(
"Failed to execute 'open' on 'EyeDropper': Color selection aborted."
);
};
const abortSignalDuring = () => {
return new DOMException('Color selection aborted.');
};
global.EyeDropper = class EyeDropper {
constructor() {}
_getColor() {
return 'rgba(255, 255, 255, 0)';
}
_setOpen() {
EyeDropper.isOpen = true;
}
_setClosed() {
EyeDropper.isOpen = false;
}
_getTimeout() {
return 50;
}
open(options) {
return new Promise((resolve, reject) => {
const signal = options?.signal;
const onAbortDuring = () => {
clearTimeout(resolveTimeout);
this._setClosed();
reject(abortSignalDuring());
};
if (signal) {
if (signal.aborted) {
reject(abortSignal());
return;
}
signal.addEventListener('abort', onAbortDuring);
}
this._setOpen();
const resolveTimeout = setTimeout(() => {
if (signal) signal.removeEventListener('abort', onAbortDuring);
this._setClosed();
resolve({ sRGBHex: this._getColor() });
}, this._getTimeout());
});
}
};