munch-ease-frontend/tests/router.guard.unauth.test.ts

20 lines
821 B
TypeScript
Raw Normal View History

2025-11-01 08:12:12 +00:00
import { describe, it, expect } from 'vitest'
describe('router guard unauthenticated redirect', () => {
it('redirects to /login with redirect query when not authenticated', async () => {
const { createAppRouter } = await import('@/router/index')
const router = createAppRouter(async () => null)
// Replace the lazy .vue login route with an inline component to avoid plugin-vue in tests
try { router.removeRoute('login') } catch (_) { /* ignore */ }
router.addRoute({ path: '/login', name: 'login', component: { template: '<div />' } })
// Navigate to a protected route that uses an inline component to avoid lazy .vue imports
await router.push('/')
const current = router.currentRoute.value
expect(current.name).toBe('login')
expect(current.query.redirect).toBe('/')
})
})