Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HttpResponse): support non-configurable status codes #2434

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Feb 20, 2025

With this fix, you will be able to do this:

new HttpResponse(null, { status: 101 })

No direct changes necessary in MSW. We should rely on FetchResponse from Interceptors, to begin with. It bakes in a bunch of useful, uncommon behaviors that are expected in the context of mocking.

@@ -1,3 +1,4 @@
import { FetchResponse } from '@mswjs/interceptors'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FetchResponse extends the global Response so it's safe to use both in Node.js and in the browser. I hope the root export of Interceptors doesn't load anything Node.js-specific (it mustn't).

@@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely a Node.js typings hiccup.

@kettanaito kettanaito marked this pull request as ready for review February 20, 2025 17:43
@kettanaito kettanaito merged commit 0cf639e into main Feb 20, 2025
22 checks passed
@kettanaito kettanaito deleted the fix/http-response-non-configurable-status branch February 20, 2025 17:44
@kettanaito
Copy link
Member Author

Released: v2.7.1 🎉

This has been released in v2.7.1!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RangeError: init["status"] must be in the range of 200 to 599, inclusive.
1 participant