Files
homelable/frontend/src/stores/__tests__/authStore.test.ts
T

31 lines
968 B
TypeScript

import { describe, it, expect, beforeEach } from 'vitest'
import { useAuthStore } from '@/stores/authStore'
describe('authStore', () => {
beforeEach(() => {
localStorage.clear()
useAuthStore.setState({ token: null, isAuthenticated: false })
})
it('starts unauthenticated', () => {
const { token, isAuthenticated } = useAuthStore.getState()
expect(token).toBeNull()
expect(isAuthenticated).toBe(false)
})
it('login sets token and isAuthenticated', () => {
useAuthStore.getState().login('my-jwt-token')
const { token, isAuthenticated } = useAuthStore.getState()
expect(token).toBe('my-jwt-token')
expect(isAuthenticated).toBe(true)
})
it('logout clears token and isAuthenticated', () => {
useAuthStore.getState().login('my-jwt-token')
useAuthStore.getState().logout()
const { token, isAuthenticated } = useAuthStore.getState()
expect(token).toBeNull()
expect(isAuthenticated).toBe(false)
})
})