Mocky Balboa API Reference
    Preparing search index...

    Client used to interface with the WebSocket server for mocking server-side network requests. And optionally integrating for mocking client-side network requests.

    Index

    Properties

    clientIdentifier: string

    Unique identifier for the client, used for continuity across the WebSocket connection enabling parallel mocking

    RouteType: {
        Both: "both";
        ClientOnly: "client-only";
        ServerOnly: "server-only";
    } = RouteType

    Convenient access to route types

    Accessors

    Methods

    • Internal

      Allows an external handler to be injected into the route handling process for dealing with client-side request interception.

      Type Parameters

      • TCallbackArgs extends unknown[]
      • TResult

      Parameters

      • options: {
            extractRequest: (...args: TCallbackArgs) => Request | Promise<Request>;
            handleResult: (
                response: undefined | ExternalRouteHandlerRouteResponse,
                ...args: TCallbackArgs,
            ) => undefined | TResult | Promise<undefined | TResult>;
        }

        options for the external route handler

        • extractRequest: (...args: TCallbackArgs) => Request | Promise<Request>

          a function that extracts a request from the arguments passed to the external handler

        • handleResult: (
              response: undefined | ExternalRouteHandlerRouteResponse,
              ...args: TCallbackArgs,
          ) => undefined | TResult | Promise<undefined | TResult>

          a function that transforms the internal result to the external handlers expected result

      Returns (...args: TCallbackArgs) => Promise<undefined | TResult>

      a function that acts as a handler for the external route handler

    • Used to connect the client to the WebSocket server. This will also identify the client on the server to enable concurrency for mocking. You need to call this method before you can register any route handlers.

      Parameters

      Returns Promise<void>

    • Disconnects the WebSocket connection. You need to run Client.connect again to reconnect.

      Returns void

      Route handlers and message handlers are not removed when the client disconnects.

    • Waits for a request to be made that matches the given URL matcher.

      Parameters

      Returns Promise<Request>

      Promise resolving to an instance of Request matching the original request dispatched by the server, rejects with an error if the request is not found within the specified timeout duration.