-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
Describe the bug
It seems like Vitest doesn't populate globalThis with the fetch() implementation from Happy DOM. However, Request and Response are populated.
This causes issues when trying to use a Request or Response object together with fetch().
Additional context
Happy DOM plans to make it easier to mock requests and improve cache handling. This will prevent that from working.
Reproduction
describe('test fetch() with Request object', () => {
it('can use a Request object with fetch()', () => {
const request = new Request('https://localhost:8080/myFile.json');
// This will crash with the error "TypeError: Failed to parse URL from [object Request]"
const response = await fetch(request);
const json = await response.json();
expect(json).not.toBeNull();
});
});System Info
System:
OS: Linux 6.11 Ubuntu 24.10 24.10 (Oracular Oriole)
CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
Memory: 4.04 GB / 14.83 GB
Container: Yes
Shell: 5.2.32 - /bin/bash
Binaries:
Node: 22.6.0 - ~/.nvm/versions/node/v22.6.0/bin/node
npm: 10.8.2 - ~/.nvm/versions/node/v22.6.0/bin/npm
bun: 1.1.34 - ~/.bun/bin/bun
Browsers:
Chrome: 130.0.6723.58
Chromium: 130.0.6723.69Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable