---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk/testing/interfaces/MockSocket.md
---
[Reference](../../../../index.md) / [@getenginex/sdk/testing](../index.md) / 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

* [`WebSocketLikeInstance`](../../interfaces/WebSocketLikeInstance.md)

## 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`](../../interfaces/WebSocketLikeInstance.md).[`readyState`](../../interfaces/WebSocketLikeInstance.md#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`](../../interfaces/WebSocketLikeInstance.md).[`addEventListener`](../../interfaces/WebSocketLikeInstance.md#addeventlistener)

***

### close()

> **close**(`code?`, `reason?`): `void`

Closes the connection.

#### Parameters

##### code?

`number`

##### reason?

`string`

#### Returns

`void`

#### Inherited from

[`WebSocketLikeInstance`](../../interfaces/WebSocketLikeInstance.md).[`close`](../../interfaces/WebSocketLikeInstance.md#close)

***

### send()

> **send**(`data`): `void`

Sends a text frame.

#### Parameters

##### data

`string`

#### Returns

`void`

#### Inherited from

[`WebSocketLikeInstance`](../../interfaces/WebSocketLikeInstance.md).[`send`](../../interfaces/WebSocketLikeInstance.md#send)
