| 139 | |
| 140 | // Returns a jest mock that represents Client.request calls |
| 141 | static addMockResponse(response: Partial<ResponseType>) { |
| 142 | const mock = jest.fn(); |
| 143 | |
| 144 | Client.mockResponses.unshift([ |
| 145 | { |
| 146 | host: '', |
| 147 | url: '', |
| 148 | status: 200, |
| 149 | statusCode: 200, |
| 150 | statusText: 'OK', |
| 151 | responseText: '', |
| 152 | responseJSON: '', |
| 153 | body: '', |
| 154 | method: 'GET', |
| 155 | callCount: 0, |
| 156 | match: [], |
| 157 | ...response, |
| 158 | asyncDelay: response.asyncDelay ?? Client.asyncDelay, |
| 159 | headers: response.headers ?? {}, |
| 160 | getResponseHeader: (key: string) => response.headers?.[key] ?? null, |
| 161 | }, |
| 162 | mock, |
| 163 | ]); |
| 164 | |
| 165 | return mock; |
| 166 | } |
| 167 | |
| 168 | static findMockResponse(url: string, options: Readonly<ApiNamespace.RequestOptions>) { |
| 169 | return Client.mockResponses.find(([response]) => { |