diff --git a/spec-main/node-spec.ts b/spec-main/node-spec.ts
index ae5fda18830..a3e4af96897 100644
--- a/spec-main/node-spec.ts
+++ b/spec-main/node-spec.ts
@@ -270,7 +270,7 @@ describe('node feature', () => {
             .then(() => w.executeJavaScript(`new Promise(resolve => {
               const connection = new WebSocket(${JSON.stringify(match[1])})
               connection.onopen = () => {
-                resolve()
+                connection.onclose = () => resolve()
                 connection.close()
               }
             })`))