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

19 lines
755 B
TypeScript
Raw Normal View History

2025-11-01 08:12:12 +00:00
import { describe, it, expect } from 'vitest'
describe('router guard refresh 401 handling', () => {
it('redirects to /login with redirect when getCurrentUser throws (e.g., refresh 401)', async () => {
const { createAppRouter } = await import('@/router/index')
const router = createAppRouter(async () => { throw new Error('401 Unauthorized') })
// Stub login route with inline component to avoid loading .vue files
try { router.removeRoute('login') } catch (_) { /* ignore */ }
router.addRoute({ path: '/login', name: 'login', component: { template: '<div />' } })
await router.push('/')
const current = router.currentRoute.value
expect(current.name).toBe('login')
expect(current.query.redirect).toBe('/')
})
})