♻️ Refactor MockWebSocket

This commit is contained in:
AzazelN28 2024-05-07 11:18:35 +02:00
parent 3bae6e4661
commit 572c6f02e2
3 changed files with 91 additions and 22 deletions

View file

@ -11,20 +11,15 @@ window.WebSocket = class MockWebSocket extends EventTarget {
}
static getByURL(url) {
return this.#mocks.get(url);
}
static waitForURL(url) {
return new Promise((resolve) => {
let intervalID = setInterval(() => {
for (const [wsURL, ws] of this.#mocks) {
if (wsURL.includes(url)) {
clearInterval(intervalID);
resolve(ws);
}
}
}, 30);
});
if (this.#mocks.has(url)) {
return this.#mocks.get(url);
}
for (const [wsURL, ws] of this.#mocks) {
if (wsURL.includes(url)) {
return ws;
}
}
return undefined;
}
#url;