| 288 | } |
| 289 | |
| 290 | async function respondWithMock(response) { |
| 291 | // Setting response status code to 0 is a no-op. |
| 292 | // However, when responding with a "Response.error()", the produced Response |
| 293 | // instance will have status code set to 0. Since it's not possible to create |
| 294 | // a Response instance with status code 0, handle that use-case separately. |
| 295 | if (response.status === 0) { |
| 296 | return Response.error() |
| 297 | } |
| 298 | |
| 299 | const mockedResponse = new Response(response.body, response) |
| 300 | |
| 301 | Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, { |
| 302 | value: true, |
| 303 | enumerable: true, |
| 304 | }) |
| 305 | |
| 306 | return mockedResponse |
| 307 | } |