title: Jest - Multiple websocket connection hangs jest
body: <p>I'm using this function which creates as many websocket connections as needed via the numberOfBots argument to test if all the clients receive the message I need.</p>
  <pre><code>function checkGameStart(numberOfBots) {
      return new Promise((resolve, reject) =&gt; {
          let clients = [];
          let connection = [];
          for (let i = 0; i &lt; numberOfBots; i++) {
              clients.push(new WebSocket('ws://127.0.0.1:8080'));
              connection.push(false);
              clients[i].onmessage = (msg) =&gt; {
                  let data = JSON.parse(msg.data);
                  if (data.title === &quot;gameStarted&quot;) {
                      connection[i] = true;
                      checkAllClientsReady();
                  }
              }
              clients[i].onerror = (err) =&gt; reject(err);
          }
          function checkAllClientsReady() {
              if (!(connection.includes(false))) {
                  resolve(true);
                  closeAllConnections();
              }
          }
          function closeAllConnections() {
              for (let i = 0; i &lt; clients; i++) {
                  clients[i].close()
              }
          }
      });
  }
  </code></pre>
  <p>In the browser, it works 100%. The browser console opens 4 connections and waits for the messages before resolving the promise. However, Jest seems to hang past 15secs which is quite odd and I'm curious as to why.</p>