Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ class WebSocket extends EventTarget {
this.#handler.socket.destroy()
}

this.#handler.readyState = states.CLOSED

if (reason) {
// TODO: process.nextTick
fireEvent('error', this, (type, init) => new ErrorEvent(type, init), {
Expand Down
18 changes: 18 additions & 0 deletions test/websocket/issue-3506.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const { test } = require('node:test')
const { WebSocket } = require('../..')
const { tspl } = require('@matteo.collina/tspl')

test('readyState is set on fail', async (t) => {
const { deepStrictEqual, completed } = tspl(t, { plan: 1 })
const ws = new WebSocket('ws://localhost:1')

t.after(() => ws.close())

ws.addEventListener('error', () => {
deepStrictEqual(ws.readyState, WebSocket.CLOSED)
})

await completed
})