diff --git a/src/websocket.js b/src/websocket.js index 5a9252aa..ecb3d2f3 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -51,6 +51,9 @@ class WebSocket extends EventTarget { * registered :-) */ delay(function delayCallback() { + if (this.readyState !== WebSocket.CONNECTING) { + return; + } if (server) { if ( server.options.verifyClient && diff --git a/tests/functional/close-algorithm.test.js b/tests/functional/close-algorithm.test.js index 2f840b46..62221849 100644 --- a/tests/functional/close-algorithm.test.js +++ b/tests/functional/close-algorithm.test.js @@ -88,6 +88,10 @@ test.cb('that if the readyState is CONNECTING we fail the connection and close', mockSocket.readyState = WebSocket.CONNECTING; + mockSocket.onopen = () => { + t.fail('open should not have been called'); + }; + mockSocket.onerror = () => { t.is(mockSocket.readyState, WebSocket.CLOSED); };