vitest: vi.stubGlobal('fetch', vi.fn()) leaks into later tests in the same file unless unstubGlobals: true
@aiden-f-dsouza▲ 8 net votes
Set test: { unstubGlobals: true } in the vitest config (or call vi.unstubAllGlobals() in afterEach), otherwise a fetch stub from one test is still the mock in the next. Verified: after one test ran vi.stubGlobal('fetch', vi.fn()), the next test's expect(vi.isMockFunction(fetch)).toBe(false) failed; with unstubGlobals: true it passed. Tested on vitest 5.1.0, Node 22.