refactor: remove any types from test files (batch 3)

Remove explicit any types from 2 test files:
- firebaseAuthStore.test.ts (10 instances)
- useMinimapSettings.test.ts (10 instances)

Changes:
- Created MockAuth type for firebase auth mocks
- Used UserCredential type for firebase user credential mocks
- Used `ReturnType<typeof func>` to derive proper store types
- Changed Record<string, any> to Record<string, unknown>

All changes pass typecheck and tests.
This commit is contained in:
Johnpaul
2026-01-22 00:16:15 +01:00
parent 94fc1f6e30
commit 06dbb0fd32
2 changed files with 44 additions and 22 deletions

View File

@@ -17,7 +17,7 @@ describe('useMinimapSettings', () => {
it('should return all minimap settings as computed refs', () => {
const mockSettingStore = {
get: vi.fn((key: string) => {
const settings: Record<string, any> = {
const settings: Record<string, unknown> = {
'Comfy.Minimap.NodeColors': true,
'Comfy.Minimap.ShowLinks': false,
'Comfy.Minimap.ShowGroups': true,
@@ -28,10 +28,12 @@ describe('useMinimapSettings', () => {
})
}
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore as any)
vi.mocked(useSettingStore).mockReturnValue(
mockSettingStore as unknown as ReturnType<typeof useSettingStore>
)
vi.mocked(useColorPaletteStore).mockReturnValue({
completedActivePalette: { light_theme: false }
} as any)
} as unknown as ReturnType<typeof useColorPaletteStore>)
const settings = useMinimapSettings()
@@ -47,9 +49,13 @@ describe('useMinimapSettings', () => {
completedActivePalette: { light_theme: false }
}
vi.mocked(useSettingStore).mockReturnValue({ get: vi.fn() } as any)
vi.mocked(useSettingStore).mockReturnValue({
get: vi.fn()
} as unknown as ReturnType<typeof useSettingStore>)
vi.mocked(useColorPaletteStore).mockReturnValue(
mockColorPaletteStore as any
mockColorPaletteStore as unknown as ReturnType<
typeof useColorPaletteStore
>
)
const settings = useMinimapSettings()
@@ -66,9 +72,13 @@ describe('useMinimapSettings', () => {
completedActivePalette: { light_theme: true }
}
vi.mocked(useSettingStore).mockReturnValue({ get: vi.fn() } as any)
vi.mocked(useSettingStore).mockReturnValue({
get: vi.fn()
} as unknown as ReturnType<typeof useSettingStore>)
vi.mocked(useColorPaletteStore).mockReturnValue(
mockColorPaletteStore as any
mockColorPaletteStore as unknown as ReturnType<
typeof useColorPaletteStore
>
)
const settings = useMinimapSettings()
@@ -85,9 +95,13 @@ describe('useMinimapSettings', () => {
completedActivePalette: { light_theme: false }
}
vi.mocked(useSettingStore).mockReturnValue({ get: vi.fn() } as any)
vi.mocked(useSettingStore).mockReturnValue({
get: vi.fn()
} as unknown as ReturnType<typeof useSettingStore>)
vi.mocked(useColorPaletteStore).mockReturnValue(
mockColorPaletteStore as any
mockColorPaletteStore as unknown as ReturnType<
typeof useColorPaletteStore
>
)
const settings = useMinimapSettings()
@@ -107,10 +121,12 @@ describe('useMinimapSettings', () => {
})
const mockSettingStore = { get: mockGet }
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore as any)
vi.mocked(useSettingStore).mockReturnValue(
mockSettingStore as unknown as ReturnType<typeof useSettingStore>
)
vi.mocked(useColorPaletteStore).mockReturnValue({
completedActivePalette: { light_theme: false }
} as any)
} as unknown as ReturnType<typeof useColorPaletteStore>)
const settings = useMinimapSettings()

View File

@@ -1,5 +1,5 @@
import { FirebaseError } from 'firebase/app'
import type { User } from 'firebase/auth'
import type { User, UserCredential } from 'firebase/auth'
import * as firebaseAuth from 'firebase/auth'
import { createPinia, setActivePinia } from 'pinia'
import type { Mock } from 'vitest'
@@ -13,6 +13,8 @@ type MockUser = Omit<User, 'getIdToken'> & {
getIdToken: Mock
}
type MockAuth = Record<string, unknown>
// Mock fetch
const mockFetch = vi.fn()
vi.stubGlobal('fetch', mockFetch)
@@ -93,7 +95,7 @@ describe('useFirebaseAuthStore', () => {
let authStateCallback: (user: User | null) => void
let idTokenCallback: (user: User | null) => void
const mockAuth = {
const mockAuth: MockAuth = {
/* mock Auth object */
}
@@ -113,7 +115,9 @@ describe('useFirebaseAuthStore', () => {
})
// Mock useFirebaseAuth to return our mock auth object
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(
mockAuth as unknown as ReturnType<typeof vuefire.useFirebaseAuth>
)
// Mock onAuthStateChanged to capture the callback and simulate initial auth state
vi.mocked(firebaseAuth.onAuthStateChanged).mockImplementation(
@@ -167,7 +171,9 @@ describe('useFirebaseAuthStore', () => {
}
)
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(
mockAuth as unknown as ReturnType<typeof vuefire.useFirebaseAuth>
)
setActivePinia(createPinia())
const storeModule = await import('@/stores/firebaseAuthStore')
@@ -241,7 +247,7 @@ describe('useFirebaseAuthStore', () => {
it('should login with valid credentials', async () => {
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.signInWithEmailAndPassword).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
const result = await store.login('test@example.com', 'password')
@@ -277,7 +283,7 @@ describe('useFirebaseAuthStore', () => {
// Set up multiple login promises
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.signInWithEmailAndPassword).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
const loginPromise1 = store.login('user1@example.com', 'password1')
@@ -295,7 +301,7 @@ describe('useFirebaseAuthStore', () => {
it('should register a new user', async () => {
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.createUserWithEmailAndPassword).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
const result = await store.register('new@example.com', 'password')
@@ -372,7 +378,7 @@ describe('useFirebaseAuthStore', () => {
// Setup mock for login
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.signInWithEmailAndPassword).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
// Login
@@ -474,7 +480,7 @@ describe('useFirebaseAuthStore', () => {
it('should sign in with Google', async () => {
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.signInWithPopup).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
const result = await store.loginWithGoogle()
@@ -507,7 +513,7 @@ describe('useFirebaseAuthStore', () => {
it('should sign in with Github', async () => {
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.signInWithPopup).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
const result = await store.loginWithGithub()
@@ -539,7 +545,7 @@ describe('useFirebaseAuthStore', () => {
it('should handle concurrent social login attempts correctly', async () => {
const mockUserCredential = { user: mockUser }
vi.mocked(firebaseAuth.signInWithPopup).mockResolvedValue(
mockUserCredential as any
mockUserCredential as unknown as UserCredential
)
const googleLoginPromise = store.loginWithGoogle()