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

Reference / @getenginex/sdk/testing / MockRealtime

MockRealtime ​

Mock realtime returned by createMockRealtime.

Properties ​

webSocket ​

readonly webSocket: WebSocketLike

Pass it in createEnginexClient({ webSocket }): each client connection becomes a MockSocket.

Methods ​

acceptPrivate() ​

acceptPrivate(topic?): void

Undoes MockRealtime.rejectPrivate: the mock goes back to answering ack. It only affects new subscribes (those of a next (re)connection or of a new subscription): what was already refused is not resent. After a block (closed + UNAUTHENTICATED), the client only reconnects when the session gets a new access token (login, refresh) — as at the gateway.

Parameters ​

topic? ​

string

Only this full topic, refused earlier with rejectPrivate(topic); without it, clears all the refusals (the general ones and the per-topic ones).

Returns ​

void

Example ​

ts
mock.rejectPrivate()
// ... the app reaches `closed` and asks for login
mock.acceptPrivate()
await enginex.auth.login({ email, password }) // new token: realtime reconnects and subscribes

connections() ​

connections(): MockSocket[]

All the connections opened so far, in order (the URL includes the token, for asserts).

Returns ​

MockSocket[]


drop() ​

drop(code?): void

Drops the current connection (a network drop): the client reconnects with backoff and fires onResync.

Parameters ​

code? ​

number

Close code (default 1006, abnormal drop).

Returns ​

void

Throws ​

Without an open connection.

Example ​

ts
mock.drop()

emit() ​

emit(topic, type, payload): void

Sends a plain data message (the gateway's multi-tenant mode) on the current connection.

Parameters ​

topic ​

string

Full topic, e.g. 'balance:mock-user-1'.

type ​

string

Message type, e.g. 'balance_update'.

payload ​

unknown

Payload as on the wire (snake_case).

Returns ​

void

Throws ​

Without an open connection.

Example ​

ts
mock.emit('balance:u-1', 'balance_update', { available: 100, change: 100, change_type: 'credit', updated_at: '2026-01-01T00:00:00Z' })

emitSequenced() ​

emitSequenced(topic, kind, seq, payload?): void

Sends a sequenced-mode message (single-tenant), with the gateway's double envelope.

Parameters ​

topic ​

string

Full topic.

kind ​

"snapshot" | "delta" | "heartbeat"

'snapshot', 'delta' or 'heartbeat'.

seq ​

number

Sequence number.

payload? ​

unknown

Payload as on the wire (default {}).

Returns ​

void

Throws ​

Without an open connection.

Example ​

ts
mock.emitSequenced('predictions:orderbook:m-1', 'snapshot', 1, { market_id: 'm-1' })
mock.emitSequenced('predictions:orderbook:m-1', 'delta', 3) // gap: the client asks for snapshot_request

rejectPrivate() ​

rejectPrivate(topic?): void

Starts answering error unauthorized to subscribes for private topics, as the gateway does with a token downgraded to anonymous. It applies to the subscribes already sent on the current connection (they are refused now) and to every new subscribe, including those of the next (re)connections, until MockRealtime.acceptPrivate: the client renews the token, tries once more and ends in closed with UNAUTHENTICATED.

Parameters ​

topic? ​

string

Only this full topic (e.g. 'balance:u-1'); without it, all the private ones (see MockRealtimeOptions.isPrivate).

Returns ​

void

Example ​

ts
mock.rejectPrivate()

sent() ​

sent(): MockSentFrame[]

Frames sent by the client on all connections, in order (type and topic).

Returns ​

MockSentFrame[]