wraith/frontend/tests/setup.ts
Vantz Stockwell f01e357647 test: frontend test suite — Vitest infrastructure, auth/connection stores, vault composable, admin middleware
28 tests across 4 spec files. Vitest + happy-dom configured with Nuxt auto-import
shims ($$fetch, navigateTo, defineNuxtRouteMiddleware) so stores and composables
resolve cleanly outside the Nuxt runtime.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 19:06:14 -04:00

39 lines
1.4 KiB
TypeScript

import { vi } from 'vitest'
import { ref, computed, onMounted, watch } from 'vue'
// -------------------------------------------------------------------
// Nuxt auto-import globals
// These are injected by Nuxt at runtime but Vitest doesn't run Nuxt,
// so we shim them here so test files can import store/composable modules
// without hitting "X is not defined" errors.
// -------------------------------------------------------------------
// $fetch — Nuxt's isomorphic fetch wrapper
global.$fetch = vi.fn()
// navigateTo — Nuxt router utility
global.navigateTo = vi.fn()
// Route middleware helpers
global.defineNuxtRouteMiddleware = vi.fn((fn: Function) => fn)
// Plugin helper (used in some plugin files, not in tests directly)
global.defineNuxtPlugin = vi.fn((fn: Function) => fn)
// Page meta (used in page components)
global.definePageMeta = vi.fn()
// Vue Composition API — re-export from Vue so stores using these
// via Nuxt auto-imports resolve correctly in Vitest
global.ref = ref
global.computed = computed
global.onMounted = onMounted
global.watch = watch
// useAuthStore — needed by middleware; forward-declared here so
// admin.ts middleware can resolve it. Individual test files override
// this with the real Pinia store instance.
// (Set to undefined by default — tests that import middleware must
// call setActivePinia first and then the real store will resolve.)
global.useAuthStore = undefined as any