You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
when trying to send a FormData request that includes a file on a test that is using jsdom,
seems like the request is not adding the content-length properly (as happens automatically on the browser/Node.js)
fetch is provided by Node.js, but FormData is provided by jsdom, so fetch doesn't know how to handle it. This is out of scope of Vitest as we don't control how environments implement their API. To make this work, you can reassign FormData to Node.js one, patch global fetch or wait for JSDOM to implement their own fetch method.
fetch is provided by Node.js, but FormData is provided by jsdom, so fetch doesn't know how to handle it. This is out of scope of Vitest as we don't control how environments implement their API. To make this work, you can reassign FormData to Node.js one, patch global fetch or wait for JSDOM to implement their own fetch method.
Ok, thanks.
Is there a similar example for one of the workaround methods?
// this works because jsdom doesn't provide `Request` and it's coming from NodeJs/undiciasyncfunctionrestoreNodeGlobals(){constnodeGlobals: any={};{constrequest=newRequest("https://test.local",{method: "POST",headers: {"content-type": "application/x-www-form-urlencoded",},});constformData=awaitrequest.formData();nodeGlobals.FormData=formData.constructor;}{constrequest=newRequest("https://test.local",{method: "POST",});constblob=awaitrequest.blob();nodeGlobals.Blob=blob.constructor;}Object.assign(globalThis,nodeGlobals);}
FYI, the similar issue has been discussed in #4043
Describe the bug
Hi,
when trying to send a FormData request that includes a file on a test that is using
jsdom
,seems like the request is not adding the content-length properly (as happens automatically on the browser/Node.js)
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-lqr5xr?file=test%2Fbasic.test.ts,vite.config.ts,package.json,package-lock.json&initialPath=__vitest__/
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: