-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Trying to pull body in POST mocks breaks mocking #2162
Comments
I have the same issue. |
@kettanaito just wanted to follow up on this and see if there is anything else that would be helpful in getting to the bottom of it. This seems like a rather large issue considering the documented behavior seems to be broken, i'm surprised there are not more reports of this. I have not tested different node versions but for what its worth i'm on v20.11.1. |
@kettanaito I am also facing the same issue, when I am trying to pull request body or formData by using async await, it breaks the handlers without any error.
|
Hi, @reintroducing. Thanks for reporting this. It's important to stress that I don't think your expected behavior applies here. The click handler for the "Test post" button doesn't send a As such, you won't be able to read this request's body as You should receive an error in that case. Do you? |
I also encourage anyone experiencing this issue to update |
@kettanaito Ah, that makes sense. Updating msw did not fix the "issue", however I made the following changes: in That method looks like this (for anyone reading along):
This now works as expected and I get no errors. Thank you! |
Prerequisites
Environment check
msw
versionBrowsers
Chromium (Chrome, Brave, etc.)
Reproduction repository
https://github.com/reintroducing/vite-msw
Reproduction steps
npm i
npm start
src/mocks/api/tour/post-test/index.ts
and comment out lines 13-15 and uncomment lines 16-22.Current behavior
When using async/await handler for post request and trying to get the body using
const body = await request.formData();
, the request fails. Note that the method can be async but just trying to get the body using await is what is causing the issue.Expected behavior
Should be able to retrieve the body and log out
foo
as the docs outline and the mock should function as expected.The text was updated successfully, but these errors were encountered: