-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
41 lines (35 loc) · 832 Bytes
/
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
class StubWebSocket {
constructor(url) {
this.url = url;
this.readyState = 0;
this.sent = [];
this.listeners = {};
}
send(data) {
this.sent.push(data);
}
close() {
this.readyState = 3;
}
addEventListener(type, listener) {
if (!this.listeners[type]) {
this.listeners[type] = [];
}
this.listeners[type].push(listener);
}
removeEventListener(type, listener) {
if (this.listeners[type]) {
this.listeners[type] = this.listeners[type].filter(l => l !== listener);
}
}
dispatch(type, event) {
if (this.listeners[type]) {
for (const listener of this.listeners[type]) {
listener(event);
}
}
}
}
global.TextEncoder = require('util').TextEncoder;
global.crypto.subtle = require('crypto').subtle;
global.WebSocket = StubWebSocket;