Closed geoidesic closed 4 weeks ago
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 https://github.com/IanVS/vitest-fetch-mock/pull/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: