diff --git a/src/interceptors/WebSocket/WebSocketServerConnection.ts b/src/interceptors/WebSocket/WebSocketServerConnection.ts index 378264d8..56150299 100644 --- a/src/interceptors/WebSocket/WebSocketServerConnection.ts +++ b/src/interceptors/WebSocket/WebSocketServerConnection.ts @@ -15,6 +15,7 @@ import { const kEmitter = Symbol('kEmitter') const kBoundListener = Symbol('kBoundListener') +const kSend = Symbol('kSend') interface WebSocketServerEventMap { open: Event @@ -63,7 +64,7 @@ export class WebSocketServerConnection { // so execute the logic on the next tick. queueMicrotask(() => { if (!event.defaultPrevented) { - this.send(event.data) + this[kSend](event.data) } }) }) @@ -203,6 +204,10 @@ export class WebSocketServerConnection { * server.send(new TextEncoder().encode('hello')) */ public send(data: WebSocketData): void { + this[kSend](data) + } + + private [kSend](data: WebSocketData): void { const { realWebSocket } = this invariant(