-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vitest error on fetching relative URLs #12
Comments
Thanks for the report, would you be willing to put together a minimal reproduction in stackblitz or codesandbox? |
@geoidesic go the exact same error, it seems it uses node-fetch underneath, its better to mock the global fetch directly |
This workaround works just fine Ofcourse set/restore global fetch back to the original in the afterEach/beforeEach it('user not logged in', async () => {
// mock your fetch
globalThis.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
const headers = new Headers({
'content-type': 'application/json',
});
console.log('incomming url: %o', input);
return new Response('{ "message": "Ok" }', { status: 200, statusText: 'ok', headers });
};
// @ts-ignore
const boot = await import('../boot/preboot');
const result = boot.default();
}); |
This might also be fixed by #24 since it will patch the global fetch. |
Closing this. Feel free to open a new issue if this still occurs in version 0.4.0 or later. |
I don't get this error if I run the fetch via the app code but via vitest using this mocking library then it gives this error:
Here's the test:
The text was updated successfully, but these errors were encountered: