Skip to content

Commit 0cf639e

Browse files
authored
fix(HttpResponse): support non-configurable status codes (#2434)
1 parent e5cca27 commit 0cf639e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/HttpResponse.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ it('creates a plain response', async () => {
1313
expect(Object.fromEntries(response.headers.entries())).toEqual({})
1414
})
1515

16+
it('supports non-configurable status codes', () => {
17+
expect(new HttpResponse(null, { status: 101 })).toHaveProperty('status', 101)
18+
})
19+
1620
describe('HttpResponse.text()', () => {
1721
it('creates a text response', async () => {
1822
const response = HttpResponse.text('hello world', { status: 201 })

src/core/HttpResponse.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FetchResponse } from '@mswjs/interceptors'
12
import type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'
23
import type { NoInfer } from './typeUtils'
34
import {
@@ -35,7 +36,7 @@ export interface StrictResponse<BodyType extends DefaultBodyType>
3536
*
3637
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
3738
*/
38-
export class HttpResponse extends Response {
39+
export class HttpResponse extends FetchResponse {
3940
constructor(body?: BodyInit | null, init?: HttpResponseInit) {
4041
const responseInit = normalizeResponseInit(init)
4142
super(body, responseInit)
@@ -167,7 +168,7 @@ export class HttpResponse extends Response {
167168
responseInit.headers.set('Content-Length', body.byteLength.toString())
168169
}
169170

170-
return new HttpResponse(body, responseInit)
171+
return new HttpResponse(body as ArrayBuffer, responseInit)
171172
}
172173

173174
/**

0 commit comments

Comments
 (0)