mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 15:40:10 +00:00
[fix] Update firebaseAuthStore tests to mock axios client
- Move axios mock setup before store import to ensure client is mocked - Set up default successful responses for customer API endpoints - Fix TypeScript issues with isAxiosError mock type
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import * as firebaseAuth from 'firebase/auth'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -5,6 +6,25 @@ import * as vuefire from 'vuefire'
|
||||
|
||||
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
||||
|
||||
// Mock axios before any imports that use it
|
||||
vi.mock('axios')
|
||||
const mockedAxios = vi.mocked(axios)
|
||||
|
||||
// Set up axios mock with default instance
|
||||
const mockAxiosInstance = {
|
||||
get: vi.fn().mockResolvedValue({
|
||||
data: { balance: { credits: 0 } },
|
||||
status: 200
|
||||
}),
|
||||
post: vi.fn().mockResolvedValue({
|
||||
data: { id: 'test-customer-id' },
|
||||
status: 201
|
||||
})
|
||||
}
|
||||
|
||||
mockedAxios.create = vi.fn().mockReturnValue(mockAxiosInstance)
|
||||
mockedAxios.isAxiosError = vi.fn().mockImplementation(() => false) as any
|
||||
|
||||
// Mock fetch
|
||||
const mockFetch = vi.fn()
|
||||
vi.stubGlobal('fetch', mockFetch)
|
||||
@@ -91,7 +111,18 @@ describe('useFirebaseAuthStore', () => {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks()
|
||||
vi.clearAllMocks()
|
||||
|
||||
// Reset axios mock responses to defaults
|
||||
mockAxiosInstance.get.mockResolvedValue({
|
||||
data: { balance: { credits: 0 } },
|
||||
status: 200
|
||||
})
|
||||
mockAxiosInstance.post.mockResolvedValue({
|
||||
data: { id: 'test-customer-id' },
|
||||
status: 201
|
||||
})
|
||||
mockedAxios.isAxiosError = vi.fn().mockImplementation(() => false) as any
|
||||
|
||||
// Mock useFirebaseAuth to return our mock auth object
|
||||
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)
|
||||
|
||||
Reference in New Issue
Block a user