Skip to content

Commit

Permalink
fix(HttpResponse): support non-configurable status codes (#2434)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito authored Feb 20, 2025
1 parent e5cca27 commit 0cf639e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/HttpResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ it('creates a plain response', async () => {
expect(Object.fromEntries(response.headers.entries())).toEqual({})
})

it('supports non-configurable status codes', () => {
expect(new HttpResponse(null, { status: 101 })).toHaveProperty('status', 101)
})

describe('HttpResponse.text()', () => {
it('creates a text response', async () => {
const response = HttpResponse.text('hello world', { status: 201 })
Expand Down
5 changes: 3 additions & 2 deletions src/core/HttpResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FetchResponse } from '@mswjs/interceptors'
import type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'
import type { NoInfer } from './typeUtils'
import {
Expand Down Expand Up @@ -35,7 +36,7 @@ export interface StrictResponse<BodyType extends DefaultBodyType>
*
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
*/
export class HttpResponse extends Response {
export class HttpResponse extends FetchResponse {
constructor(body?: BodyInit | null, init?: HttpResponseInit) {
const responseInit = normalizeResponseInit(init)
super(body, responseInit)
Expand Down Expand Up @@ -167,7 +168,7 @@ export class HttpResponse extends Response {
responseInit.headers.set('Content-Length', body.byteLength.toString())
}

return new HttpResponse(body, responseInit)
return new HttpResponse(body as ArrayBuffer, responseInit)
}

/**
Expand Down

0 comments on commit 0cf639e

Please sign in to comment.