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
Define response mocking API #4
Comments
Support for multiple API may also be a viable option. |
To expand on functional composition, consider msw.get('...', (req, { response, status, json }) => {
return response(
status(301),
json({ message: 'Item has been moved' }),
)
})
... // Inject context in another file
msw.init({ response: ..., status: ..., json: ... }) You can also implement Express style |
@bebraw yeah, this is one of the ways to group essential utils without having to explicitly import them. Maybe one thing I would move aside is the |
I've adopted the functional composition approach. You can see the example of usage in the current README. With something like I like the current signature, and especially adore that a developer can write his own mocking helpers following a straightforward API. msw.get('https://api.com/user/:username', (req, res, { status, json }) => {
return res(
status(301, 'Moved far away'),
json({ message: `The user "${req.params.username}" has been moved` }),
)
}) |
Response mocking API has been defined in favor of functional composition. I will add/update any relevant documentation once GitBook unblocks my account. Closing this issue, but welcome any succeeding discussion on the topic. |
What:
I suggest to define a response mocking API supported by the library.
Why:
It is essential to have a usable API to define response mocks.
How:
Mimic
res
fromexpress
Example:
Pros:
res
ObjectCons:
res
Object mutationres
from express is a custom Object)Functional composition
Example:
Pros:
Cons:
json
orstatus
would need to be explicitly imported (may be solved by exposing them as a handler function parameters)The text was updated successfully, but these errors were encountered: