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
feat: add HttpResponse.html() #2140
base: main
Are you sure you want to change the base?
feat: add HttpResponse.html() #2140
Conversation
Hey, @scruffymongrel! Thanks for proposing this. I will have to think about this for a while. The |
Thanks for taking a look. I'm not sure what you mean by "the stance regarding custom helper methods", but let me know if there's anything I can do to help :) |
@scruffymongrel can you please share your use case for this? When would you want to respond with HTML to a fetch request? |
Sorry for the delay in getting back to you -- this fell off my list and I just remembered I owed you a response! I was originally intending to use MSW to work with htmx, mocking responses which would be chucks of HTML. Unfortunately htmx uses XHR rather than fetch, so I'm guessing that this would be a bad fit. There was discussion around htmx moving to fetch in future versions but it doesn't seem to a priority at the moment. If I've missed something and there is a way for MWS to work with XHR, I'd be keen to know more. Otherwise, feel free to close this PR. |
Why? MSW is client-agnostic and works with XHR as well as it does with I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fantastic. Thank you for your work on this, @scruffymongrel. Marking it as a release candidate. Expect it to land in the next minor version. I will look at pending bugfixes, release those first, then this.
Excellent! Was disappointed when I thought MSW was restricted to just fetch, so this is great news. Glad to hear that |
Add the ability to return html responses, enabling users to mock hypermedia APIs.
It mimics
HttpResponse.xml()
, except it creates aResponse
instance with theContent-Type: text/html
.