Files
sanguo_vnpy_v2/frontend/tests/auth.test.ts
T
claude_dev a5b00c2dea feat(frontend): S0 Vue3 脚手架 + auth + Layout shell(4入口,模拟/实盘灰显)
- Vite+TS+ElementPlus+ECharts+Pinia+Router+Axios
- auth store + JWT axios 拦截器 + 路由守卫
- 登录页 + Layout(侧栏 4 入口,回测/投研 active,模拟/实盘 disabled)
- 占位页(backtest/factor,S1/S2 填充)
- vitest auth store 3 tests passed + build 通过(dist 生成)
2026-07-07 05:56:24 +08:00

36 lines
1.0 KiB
TypeScript

import { setActivePinia, createPinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import { useAuthStore } from '@/stores/auth'
describe('auth store', () => {
beforeEach(() => {
localStorage.clear()
setActivePinia(createPinia())
})
it('starts unauthenticated', () => {
const auth = useAuthStore()
expect(auth.isAuthenticated).toBe(false)
expect(auth.token).toBe(null)
})
it('setToken stores token + username and authenticates', () => {
const auth = useAuthStore()
auth.setToken('jwt-xyz', 'admin')
expect(auth.token).toBe('jwt-xyz')
expect(auth.username).toBe('admin')
expect(auth.isAuthenticated).toBe(true)
expect(localStorage.getItem('token')).toBe('jwt-xyz')
})
it('logout clears token + username', () => {
const auth = useAuthStore()
auth.setToken('jwt-xyz', 'admin')
auth.logout()
expect(auth.token).toBe(null)
expect(auth.username).toBe(null)
expect(auth.isAuthenticated).toBe(false)
expect(localStorage.getItem('token')).toBe(null)
})
})