mswjs / jest-fixed-jsdom

A superset of the JSDOM environment for Jest that respects Node.js globals.
https://npm.im/jest-fixed-jsdom
51 stars 5 forks source link

Using Request with a relative url doesn't work #23

Closed nathanhannig closed 1 day ago

nathanhannig commented 3 days ago

I noticed in testing a project that uses a relative path instead of an absolute path when creating a Request

new Request('/relative/path', {
  body: JSON.stringify(data),
}

A type error is thrown

TypeError: Failed to parse URL from /relative/path
Cause:
TypeError: Invalid URL

I believe the browser implementation of Request allows relative path because it can determine the base url, while the node version of Request does not.

kettanaito commented 2 days ago

How does this behave in HappyDOM? Node's Request won't support relative URLs because there's nothing to be relative to in Node.

nathanhannig commented 2 days ago

hmm, switching to "@happy-dom/jest-environment", I am using MSW (node) with my project and am hitting an issue

ReferenceError: BroadcastChannel is not defined

> 1 | import { http, HttpResponse } from "msw";
    | ^