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();
});
});
Describe the bug
It seems like Vitest doesn't populate
globalThis
with thefetch()
implementation from Happy DOM. However,Request
andResponse
are populated.This causes issues when trying to use a
Request
orResponse
object together withfetch()
.Additional context Happy DOM plans to make it easier to mock requests and improve cache handling. This will prevent that from working.
Reproduction
System Info
Used Package Manager
npm
Validations