export type Rule = { /** HTTP method to match (e.g. `"GET"`, `"POST"`). */ method: string; /** URL string or RegExp to match against the request URL. */ url: string | RegExp; /** The mocked response body returned to the client. */ response: unknown; /** Unique identifier for this mock rule, used with `waitForRequest`. */ alias: string; /** Whether this rule has been matched by an actual request. Set automatically by the service worker. */ executed?: boolean; /** * The parsed request body sent by the client. * For JSON requests this is the parsed object, for form data an object of key/value pairs, for text a string. * Access fields directly: `rule.request.email`, **not** `rule.request.body.email`. */ request?: any; /** HTTP status code for the mocked response (default: `200`). */ status?: number; /** Headers to include in the mocked response. */ responseHeaders?: Record; /** Whether the `url` field should be treated as a regex pattern. */ urlRegex?: boolean; /** Delay in milliseconds before returning the mocked response. */ delay?: number; /** Number of times this rule has been matched. Updated automatically by the service worker. */ hitCount?: number; }; export interface Options { /** HTTP method to match (e.g. `"GET"`, `"POST"`). */ method: string; /** URL string or RegExp to match against the request URL. */ url: string | RegExp; /** The mocked response body returned to the client. */ response: unknown; /** HTTP status code for the mocked response (default: `200`). */ status?: number; /** Headers to include in the mocked response. */ responseHeaders?: Record; /** Whether the `url` field should be treated as a regex pattern. */ urlRegex?: boolean; /** Delay in milliseconds before returning the mocked response. */ delay?: number; } /** * Initialize the mocking service worker. * Call this once before using `mockRequest` or `waitFor`. */ export declare const initRequestMocking: (path?: string) => Promise; /** * Mock a network request. * * @param alias Identifier for the mock rule. Useful for `waitFor()`. * @param options Options to configure the mock: * - `method`: HTTP method ("GET", "POST", …) * - `url`: URL string or RegExp to match * - `response`: Body of the mocked response * - `status`: (optional) HTTP status code (default: 200) * - `responseHeaders`: (optional) Response headers * - `urlRegex`: (optional) Whether the URL is a regex (default: false) * - `delay`: (optional) Delay in ms before returning the response * * @example * ```ts * mockRequest("getUser", { * method: "GET", * url: /\/api\/user\/\d+/, * response: { id: 1, name: "Kevin" }, * status: 200, * responseHeaders: { "x-mock": "true" } * }); * ``` */ export declare const mockRequest: (alias: string, options: Options) => Promise; /** * wait for a list of mocked requests to be made. * @param aliases The aliases of the mock rules to wait for * @returns The matched rules (with body if applicable) * @example * ```ts * await waitForRequests(["getUser", "postComment"]); * ``` */ export declare const waitForRequests: (aliases: string[]) => Promise; /** * Wait for a mocked request to be made. * @param alias The alias of the mock rule to wait for * @param retries The number of retries to make * @param retryDelay The delay between retries * @returns The matched rule (with body if applicable) */ export declare const waitForRequest: (alias: string, retries?: number, retryDelay?: number) => Promise; /** * Get the current list of request mock rules. * @returns The current list of request mock rules. */ export declare const getRequestMockRules: () => Rule[]; /** * Clear all request mock rules. */ export declare const clearRequestMockRules: () => void; /** * Get the number of times a specific mock rule was hit. * @param alias The alias of the mock rule * @returns The number of times the rule was matched */ export declare const getRequestCount: (alias: string) => number; /** * Get a snapshot of all mock rule hit counts. * @returns An object mapping rule aliases to their hit counts */ export declare const getRequestCounts: () => Record; /** * Reset the initialized state. Only use in tests. * @internal */ export declare const resetMockingState: () => void;