import type { CapturedRequest } from './types.js'; import type { NetworkInterceptor } from './network_interceptor.js'; /** * Options for network polling. */ export interface NetworkPollingOptions { /** * The maximum time to wait for the condition to be true. * Default is 500ms. */ timeout?: number; /** * The time to wait between checks. * Default is 25ms. */ interval?: number; } /** * A class that provides assertion APIs for network requests. */ export declare class NetworkAssert { #private; /** * The interceptor that this assertion class is attached to. */ protected interceptor: NetworkInterceptor; constructor(interceptor: NetworkInterceptor); /** * Asserts the mock intercepted at least one request. * * @example * ```ts * await button.click() * await mock.assert.called() * ``` * * @useWhen You need to verify that a network call occurred, but the exact number of times * or the specific payload does not matter. * @avoidWhen You expect the network call to happen exactly once. Use `calledOnce()` * instead to prevent false positives from duplicate requests. */ called(message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock intercepted exactly zero requests. * * Note: This method polls for 500ms to ensure no delayed or background requests * arrive shortly after the assertion is called. * * @example * ```ts * await mock.assert.notCalled() * ``` * * @useWhen Ensuring that an action did NOT trigger a network request * (e.g. validating frontend cache hits or form validation failures). */ notCalled(message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock intercepted exactly one request. * * @example * ```ts * await mock.assert.calledOnce() * ``` * * @useWhen You want to verify that an event triggers exactly one network request, * preventing bugs where components accidentally fire requests twice. */ calledOnce(message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock intercepted exactly two requests. * * @example * ```ts * await mock.assert.calledTwice() * ``` * * @useWhen Verifying retry logic, duplicate submissions, or flows that intentionally trigger the same endpoint twice. */ calledTwice(message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock intercepted exactly `n` requests. * * @param n The exact number of times the mock should have been called. * * @example * ```ts * await mock.assert.callCount(3) * ``` * * @useWhen You expect a specific, dynamic number of network requests (e.g., polling, batch processing, or looping). */ callCount(n: number, message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock intercepted at least one request matching the provided partial request object. * * @param match A partial `CapturedRequest` describing the fields to match (e.g., `method`, `body`, * `headers`, `query`). * * @example * ```ts * await mock.assert.calledWith({ * method: 'POST', * body: '{"username":"alice"}' * }) * ``` * * @useWhen Verifying that the application sends the correct payload, HTTP method, or authentication * headers during a network request. */ calledWith(match: Partial, message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock did not intercept any requests matching the provided partial request object. * * Note: This method polls for 500ms to ensure no delayed or background requests * match the criteria shortly after the assertion is called. * * @param match A partial `CapturedRequest` describing the fields that should NOT be present in any request. * * @example * ```ts * await mock.assert.notCalledWith({ method: 'DELETE' }) * ``` * * @useWhen Validating that sensitive data is not sent, or ensuring that specific unwanted operations * are not triggered. */ notCalledWith(match: Partial, message?: string, options?: NetworkPollingOptions): Promise; /** * Asserts the mock intercepted exactly one request matching the provided partial request object. * * @param match The partial request object describing the fields to match. * * @example * ```ts * await mock.assert.calledOnceWith({ * method: 'PUT', * query: { id: '123' } * }) * ``` * * @useWhen You want strict validation that a specific request happened exactly once with a specific payload, * preventing duplicate submissions. */ calledOnceWith(match: Partial, message?: string, options?: NetworkPollingOptions): Promise; }