rest-vir - v2.2.0
    Preparing search index...

    Class MockWebSocket

    A mock CommonWebSocket implementation for unit tests. Drop-in replacement for the global WebSocket constructor passed to RestVirClient.connectWebSocket's webSocketConstructor param. The test then drives the mock via getLastMockWebSocket to dispatch synthetic events, inspect captured constructor args, or capture outbound client sends via MockWebSocket.sendCallback.

    const ws = await client.connectWebSocket(myWebSocketDefinition, {
    webSocketConstructor: MockWebSocket,
    });

    getLastMockWebSocket().sendFromHost({event: 'hello'});

    Implements

    Index

    Constructors

    Properties

    capturedConstructorArgs: {
        protocols: string[] | undefined;
        url: string;
        webSocket: WebSocketDefinition;
    }
    listeners: Partial<
        {
            [EventName in keyof CommonWebSocketEventMap]: Set<
                (event: CommonWebSocketEventMap[EventName]) => MaybePromise<void>,
            >
        },
    > = {}
    readyState: CommonWebSocketState = CommonWebSocketState.Connecting

    A WebSocket.readyState property that is compatible with the native property (https://developer.mozilla.org/docs/Web/API/WebSocket/readyState) and the ws package's property (https://github.com/websockets/ws/blob/HEAD/doc/ws.md#websocketreadystate)

    sendCallback: ((data: unknown) => void) | undefined

    If set, this callback is invoked with the parsed payload every time the client calls send. Use it to assert on what the client tried to send.

    Methods