/** * Mock Fetcher for testing Cloudflare Workers Service Bindings * * Provides a mock implementation of the Fetcher interface used for * Worker-to-Worker communication via Service Bindings. * * @example * ```typescript * const presetsApi = createMockFetcher(); * * // Setup mock responses * presetsApi._setupResponse('/api/v1/presets', { * presets: [{ id: '1', name: 'Test Preset' }], * total: 1, * }); * * // Use in tests * const env = { PRESETS_API: presetsApi as unknown as Fetcher }; * * // Assert calls were made * expect(presetsApi._calls).toHaveLength(1); * expect(presetsApi._calls[0].url).toContain('/api/v1/presets'); * expect(presetsApi._calls[0].method).toBe('GET'); * * // Reset between tests * presetsApi._reset(); * ``` */ /** * Recorded fetch call for assertions */ export interface MockFetchCall { url: string; method: string; headers: Record; body?: string; timestamp: number; } /** * Mock response configuration */ export interface MockResponseConfig { status?: number; headers?: Record; body?: unknown; } /** * Configuration options for the mock fetcher */ export interface MockFetcherConfig { /** Maximum number of calls to keep in history (prevents memory leaks). Default: 1000 */ maxCallHistory?: number; } /** * Extended mock Fetcher with test helpers */ export interface MockFetcher { fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise; /** Array of all fetch calls made (for assertions). Limited to maxCallHistory entries. */ _calls: MockFetchCall[]; /** Setup a response for a specific path pattern */ _setupResponse: (pathPattern: string | RegExp, response: unknown, config?: Omit) => void; /** Setup a custom response handler */ _setupHandler: (handler: (url: string, init?: RequestInit) => Promise | Response) => void; /** Reset calls and response configurations */ _reset: () => void; /** Set default response for unmatched requests */ _setDefaultResponse: (response: unknown, config?: Omit) => void; /** Set the maximum call history size (for memory management) */ _setMaxCallHistory: (max: number) => void; } /** * Creates a mock Fetcher for testing Service Bindings * * The mock tracks all fetch calls and supports configuring * responses for specific URL patterns. * * @param config - Optional configuration for the mock fetcher * @returns A mock Fetcher that can be cast to Fetcher */ export declare function createMockFetcher(config?: MockFetcherConfig): MockFetcher; //# sourceMappingURL=fetcher.d.ts.map