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
Custom response transformer API #8
Comments
Currently is possible to provide custom response transformers as long as they follow this call signature: import { MockedResponse } from 'msw'
const myCustomTransformer = (res: MockedResponse) => res Most likely you'd be introducing your own high-order functions that return response transformers. Here's an example: import { MockedResponse } from 'msw'
const halJson = (body: Record<string, any>) => {
return (res: MockedResponse) => {
res.headers.set('Content-Type', 'application/hal+json')
res.body = JSON.stringify(body)
return res
}
} This is exactly how standard |
I've added a recipe to the documentation on how to create your Custom context utility. It would be nice to add an integration test for such custom utility before closing this task. |
Example of a custom response transformer is illustrated as a context utility function In the test above it's being used with a custom request handler and, thus, is provided in the |
What:
I suggest to add a full support for custom response transformers.
Why:
With the functional composition it is easy to create custom response transformers.
text
,json
,delay
, etc.) so the end developer may combine them to their liking.How:
The text was updated successfully, but these errors were encountered: