test(web): add frontend unit test baseline (#5451)

This commit is contained in:
fatedier
2026-07-28 01:27:35 +08:00
committed by GitHub
parent 2175557d48
commit 00c24e39bb
12 changed files with 1866 additions and 17 deletions

25
web/test/setup.ts Normal file
View File

@@ -0,0 +1,25 @@
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
})