mirror of
https://github.com/fatedier/frp.git
synced 2026-07-28 20:59:18 +08:00
26 lines
698 B
TypeScript
26 lines
698 B
TypeScript
import { enableAutoUnmount } from '@vue/test-utils'
|
|
import { afterAll, afterEach, vi } from 'vitest'
|
|
|
|
const originalFetch = globalThis.fetch
|
|
const blockedFetch = vi.fn(async () => {
|
|
throw new Error('Real network requests are disabled in unit tests')
|
|
})
|
|
|
|
globalThis.fetch = blockedFetch as typeof fetch
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks()
|
|
vi.unstubAllGlobals()
|
|
vi.clearAllMocks()
|
|
globalThis.fetch = blockedFetch as typeof fetch
|
|
document.body.innerHTML = ''
|
|
})
|
|
|
|
// Vitest runs afterEach hooks in reverse registration order, so wrappers are
|
|
// unmounted before the cleanup hook above clears the DOM.
|
|
enableAutoUnmount(afterEach)
|
|
|
|
afterAll(() => {
|
|
globalThis.fetch = originalFetch
|
|
})
|