---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk/testing/interfaces/MockRealtime.md
---
[Reference](../../../../index.md) / [@getenginex/sdk/testing](../index.md) / MockRealtime

# MockRealtime

Mock realtime returned by [createMockRealtime](../functions/createMockRealtime.md).

## Properties

### webSocket

> `readonly` **webSocket**: [`WebSocketLike`](../../type-aliases/WebSocketLike.md)

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

## Methods

### acceptPrivate()

> **acceptPrivate**(`topic?`): `void`

Undoes [MockRealtime.rejectPrivate](#rejectprivate): the mock goes back to answering `ack`. It only affects
**new** `subscribe`s (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`](MockSocket.md)\[]

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

#### Returns

[`MockSocket`](MockSocket.md)\[]

***

### 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 `subscribe`s for private topics, as the gateway does
with a token downgraded to anonymous. It applies to the `subscribe`s **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](#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](MockRealtimeOptions.md#isprivate)).

#### Returns

`void`

#### Example

```ts
mock.rejectPrivate()
```

***

### sent()

> **sent**(): [`MockSentFrame`](MockSentFrame.md)\[]

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

#### Returns

[`MockSentFrame`](MockSentFrame.md)\[]
