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
readonlycloseEvent: {code:number; } |undefined
How the connection ended (the client's close or the test's drop), or undefined if open.
frames
readonlyframes: readonlyRecord<string,unknown>[]
Frames that the client sent on this connection, already decoded (with id, when sent).
readyState
readonlyreadyState:number
Connection state: 1 when open (WebSocket.OPEN).
Inherited from
WebSocketLikeInstance.readyState
url
readonlyurl: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
send()
send(
data):void
Sends a text frame.
Parameters
data
string
Returns
void