| 85 | * Creates a mock error fetch function. |
| 86 | */ |
| 87 | export function createErrorFetch(errorMessage: string, status = 400) { |
| 88 | const error = new Error(errorMessage) |
| 89 | ;(error as Error & { status: number }).status = status |
| 90 | |
| 91 | if (status < 0) { |
| 92 | const mockFn = vi.fn().mockRejectedValue(error) |
| 93 | ;(mockFn as MockFetch).preconnect = vi.fn() |
| 94 | return mockFn as MockFetch |
| 95 | } |
| 96 | |
| 97 | const mockFetchConfig: MockFetchResponse = { |
| 98 | ok: false, |
| 99 | status, |
| 100 | statusText: errorMessage, |
| 101 | json: { error: errorMessage, message: errorMessage }, |
| 102 | } |
| 103 | |
| 104 | const baseMockFetch = createBaseMockFetch(mockFetchConfig) |
| 105 | ;(baseMockFetch as MockFetch).preconnect = vi.fn() |
| 106 | |
| 107 | return baseMockFetch as MockFetch |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Helper class for testing tools with controllable mock responses |