-
-
Notifications
You must be signed in to change notification settings - Fork 274
Description
Describe the bug
I wish I could share a detailed explanation of what I'm seeing... but I lack the time and understanding to go deep into what's going on.
I'm setting up msw in my project that runs integration tests with vitests and sets happy-dom as the running environment.
When mocking a POST request, I get the following error
TypeError: Cannot set property body of #<Request> which has only a getter
at Function.cloneBodyStream (file:///Users/sebastianbalay/projects/stilla-server/node_modules/happy-dom/lib/fetch/utilities/FetchBodyUtility.js:130:32)
To Reproduce
I don't know exactly what's different from my test suite that causes this crash, but all I'm doing is mocking a POST request with MSW.
Feel free to ask follow up question and I'll do my best to answer.
Expected behavior
Not crash
Suggested solution
Looking around the happy-dom codebase, it seems that request objects use symbol to access read-write versions of its attributes, so the fix for this issue is maybe changing https://github.com/capricorn86/happy-dom/blob/v20.0.11/packages/happy-dom/src/fetch/utilities/FetchBodyUtility.ts#L149 with:
// use symbol accessors instead of requestOrResponse.body = stream1;
requestOrResponse[PropertySymbol.body] = stream1;
I applied that patch locally and things seem to be working.