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

REST toHandlers() PUT and POST do not work with @mswjs/http-middleware due to req.body being a string #293

Open
lgibso34 opened this issue Nov 12, 2023 · 0 comments

Comments

@lgibso34
Copy link

lgibso34 commented Nov 12, 2023

I noticed this message about this lib being in maintenance mode but I hope this bug is big enough to fix or has an easy solution.

data/src/model/generateRestHandlers.ts line 200 and 217 both pass req.body to model methods that expect the data as a JS object but instead receive a string.

I have an ExpressJS server setup using MSW mock API endpoints with @mswjs/http-middleware's createMiddleware(...handlers). That middleware has these lines that always convert makes sure that req.body as a string (see issue).

I attempted to make a merge request to fix this but there were already some Jest tests failing on main and didn't know how to solve them. In this test the node-fetch fetch is catching the errors thrown by the mock server instead of the withErrors HOF and no longer passing. Ironically the POST and PUT's are having this issue. If you add fetch().catch it will catch it there but seems unintended.

Anyways, I hope we can find a way to fix this so that these libraries can work together in harmony.
Thank you!

EDIT: The issue may be more on the http-middleware library to solve. Like an optional alwaysParseReqBodyAsString: boolean option or something.

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

No branches or pull requests

1 participant