diff --git a/packages/dev-middleware/src/__tests__/FetchUtils.js b/packages/dev-middleware/src/__tests__/FetchUtils.js index 1bc4735c87fb..d85df1ae1c9b 100644 --- a/packages/dev-middleware/src/__tests__/FetchUtils.js +++ b/packages/dev-middleware/src/__tests__/FetchUtils.js @@ -11,6 +11,7 @@ import type {JSONSerializable} from '../inspector-proxy/types'; import type {RequestOptions} from 'undici'; +import {STATUS_CODES} from 'node:http'; import {Agent, request} from 'undici'; /** @@ -80,12 +81,19 @@ export function withFetchSelfSignedCertsForAllTests( // accept a dispatcher from the undici package: Node 26 rejects one from // undici 6. The package's own `fetch` throws under Jest, whose // `performance` global lacks `markResourceTiming`. + // The mock answers what these tests ask: a URL, and a response with a + // body. It follows no redirects, takes no `Request` object, and keeps no + // headers; a 204 or 304 response would throw, since a `Response` with + // those statuses cannot have a body. fetchSpy.mockImplementation(async (url, options) => { const {statusCode, body} = await request(url.toString(), { ...options, dispatcher: selfSignedCertDispatcher, }); - return new Response(await body.text(), {status: statusCode}); + return new Response(await body.text(), { + status: statusCode, + statusText: STATUS_CODES[statusCode] ?? '', + }); }); });