This version (v0.7) has not been published to npm yet.
Skip to content

Reference / @getenginex/sdk/testing / MockSocket

MockSocket ​

Connection opened by the client against the mock: it imitates the browser WebSocket (readyState, send, close, addEventListener) and exposes what the test needs to check.

Extends ​

Properties ​

closeEvent ​

readonly closeEvent: { code: number; } | undefined

How the connection ended (the client's close or the test's drop), or undefined if open.


frames ​

readonly frames: readonly Record<string, unknown>[]

Frames that the client sent on this connection, already decoded (with id, when sent).


readyState ​

readonly readyState: number

Connection state: 1 when open (WebSocket.OPEN).

Inherited from ​

WebSocketLikeInstance.readyState


url ​

readonly url: string

Connection URL, with the ?token= (for asserts; the SDK never exposes it this way).

Methods ​

addEventListener() ​

addEventListener(type, listener): void

Subscribes to open, message (with event.data as text), close and error. Realtime subscribes to all four; reconnection is driven by close (error is subscribed only so it is not left without a listener).

Parameters ​

type ​

"message" | "error" | "close" | "open"

Event name.

listener ​

(event) => void

Called on each event.

Returns ​

void

Inherited from ​

WebSocketLikeInstance.addEventListener


close() ​

close(code?, reason?): void

Closes the connection.

Parameters ​

code? ​

number

reason? ​

string

Returns ​

void

Inherited from ​

WebSocketLikeInstance.close


send() ​

send(data): void

Sends a text frame.

Parameters ​

data ​

string

Returns ​

void

Inherited from ​

WebSocketLikeInstance.send