Documentation
    Preparing search index...

    Interface MockRouteContext<TState>

    Per-request context handed to a route.

    const route = ({ message, reply }: MockRouteContext<{ items: string[] }>) => {
    reply({ items: [] });
    };
    interface MockRouteContext<TState> {
        clock: MockClock;
        message: NappletMessage & Record<string, unknown>;
        rng: SeededRng;
        runtime: ServiceRuntimeContext | undefined;
        send: (msg: NappletMessage) => void;
        state: TState;
        windowId: string;
        fail(error: string, fields?: Record<string, unknown>): void;
        push(message: NappletMessage): void;
        reply(fields?: Record<string, unknown>): void;
    }

    Type Parameters

    • TState
    Index

    Properties

    clock: MockClock

    Clock from the factory options.

    message: NappletMessage & Record<string, unknown>

    Inbound envelope (already matched by exact type).

    Seeded generator shared by the mock instance.

    runtime: ServiceRuntimeContext | undefined

    Runtime context when attached via onRegistered.

    send: (msg: NappletMessage) => void

    Raw send callback supplied by the runtime for this request.

    state: TState

    Mutable mock state.

    windowId: string

    Requesting napplet window.

    Methods

    • Send ${message.type}.result with { id, error } and any extra fields.

      Parameters

      • error: string
      • Optionalfields: Record<string, unknown>

      Returns void

    • Send ${message.type}.result carrying the request id and fields. Honors latencyMs from the factory options.

      Parameters

      • Optionalfields: Record<string, unknown>

      Returns void