-
-
Notifications
You must be signed in to change notification settings - Fork 474
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
Axios call with data doesn't match predicate with same path in 2.x #1929
Comments
I have the exact same problem 🙁 |
Hi @jc-samcart, wondering if you were able to find a workaround for this issue? I am experiencing it as well |
@ilyaulyanov Not yet. I assumed I was doing something wrong rather than it being a code issue, so I've just been putting off upgrading. |
I suspect this is the same problem as #1931. Jest -> JSDOM -> core-js -> cannot call |
Root causeSo if we dive deeper into what causes the response error, we can find this: error: ReferenceError: structuredClone is not defined
at cloneBody (/msw-example/node_modules/undici/lib/fetch/body.js:277:21)
at cloneRequest (/msw-example/node_modules/undici/lib/fetch/request.js:807:23)
at Request.clone (/msw-example/node_modules/undici/lib/fetch/request.js:717:27)
at HttpHandler.<anonymous> (/msw-example/node_modules/msw/lib/core/handlers/RequestHandler.js:116:43) Somewhere along the line, the XMLHttpRequest interceptor has called
Based on the error, the SolutionThere is no solution to this. Node.js doesn't export the I recommend migrating to Vitest. Vitest respects your test environment and preserves Node.js globals even if using JSDOM. You are quite blocked by the obsolete tooling that at this point, so migrating to modern tooling is the way to go. |
Regarding forwarding the original error, it's like I suspected: your request client will control whether that error is forwarded at all. For example, Axios uses XHR when it runs in JSDOM, and erroring an XMLHttpRequest doesn't accept any error as an argument (see this). Since using XHR is Axios' choice, you see how request client you are using controls how much information you get in case of errors. |
@kettanaito Appreciate your time looking at this. Just went through the process of updating to vitest using this nifty script and then the msw codemods. Everything is working as expected. Thank you! |
Prerequisites
Environment check
msw
versionNode.js version
v20.9.0
Reproduction repository
https://github.com/jc-samcart/msw-example
Reproduction steps
yarn test
Current behavior
I have created a handler for posting to the bananas endpoint. When I make calls to this endpoint with axios, it only is captured if I don't provide any data to the post via axios. If data is provided, I receive AxiosError: Network Error
This post request works:
This post throws an error:
Expected behavior
I would expect both axios post calls to match the handler. This did work in 1.x and I only encountered this error when upgrading to 2.x
The text was updated successfully, but these errors were encountered: