/** * Fetch mock utilities for testing * * Provides utilities for mocking the global fetch function. * For more complex scenarios, consider using MSW (Mock Service Worker). * * @example * ```typescript * // Simple mock * const mockFetch = setupFetchMock({ data: 'test' }); * * // Make request * const response = await fetch('/api/test'); * const data = await response.json(); * * // Assert * expect(data).toEqual({ data: 'test' }); * expect(mockFetch.calls).toHaveLength(1); * * // Reset * mockFetch.restore(); * ``` */ type MockResponseInit = { status?: number; statusText?: string; headers?: Record; }; /** * Mock fetch tracking interface */ export interface MockFetchTracker { /** All recorded fetch calls */ calls: Array<{ url: string; init?: RequestInit; }>; /** Restore original fetch */ restore: () => void; /** Clear recorded calls */ clear: () => void; /** Update mock response */ setResponse: (body: unknown, init?: MockResponseInit) => void; } /** * Sets up a simple fetch mock that returns a fixed response * * @param responseBody - The response body (will be JSON stringified) * @param responseInit - Optional response configuration * @returns A tracker object with calls array and restore function */ export declare function setupFetchMock(responseBody: unknown, responseInit?: MockResponseInit): MockFetchTracker; /** * Sets up a fetch mock with custom handler * * @param handler - Function to handle fetch requests * @returns A tracker object with calls array and restore function */ export declare function setupFetchMockHandler(handler: (url: string, init?: RequestInit) => Promise | Response): MockFetchTracker; /** * Creates a mock Response object * * @param body - Response body * @param init - Response init options * @returns A Response object */ export declare function createMockResponse(body: unknown, init?: MockResponseInit): Response; export {}; //# sourceMappingURL=fetch.d.ts.map