Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TLDR:
The solution is to either:
option 1 is not possible because the current tests require access top the DOM
AI explanation of issue:
What changed between versions 2.3.5 and 2.5.0 that might cause TransformStream errors in Jest?
Several changes shipped in MSW’s version 2.5.x. One of the notable changes was more thorough usage of the Web Streams API (which includes classes like TransformStream). The Web Streams API is natively available in modern browsers and in newer versions of Node.js (≥ 18). In older environments (or certain test runners), the TransformStream global may not exist by default, leading to the error:
ReferenceError: TransformStream is not defined
Why does this happen in Jest?
• Jest’s default test environment (which is often jest-environment-jsdom) may not include the TransformStream global.
• If you’re using an older version of Node.js (like Node 14 or 16) along with Jest, you may also be missing the global Web Streams classes.
As of MSW 2.5.x, the library expects TransformStream (and possibly other parts of the Web Streams API) to be present. If it’s not, you’ll see the ReferenceError.
Even though you’re on Node 20 (which natively supports the Web Streams API), you can still get ReferenceError: TransformStream is not defined if your test environment (usually JSDOM in Jest) doesn’t expose the TransformStream global. In other words, Node itself may have TransformStream, but JSDOM (or another test environment) might not.