mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 02:32:18 +00:00
[test] Fix axios mocking in firebaseAuthStore tests
Use vi.mock() with factory function to ensure axios mock is set up before module imports. This fixes test failures caused by the store creating axios client at module level. Fixes test execution in CI
This commit is contained in:
@@ -7,23 +7,28 @@ import * as vuefire from 'vuefire'
|
|||||||
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
||||||
|
|
||||||
// Mock axios before any imports that use it
|
// Mock axios before any imports that use it
|
||||||
vi.mock('axios')
|
vi.mock('axios', () => {
|
||||||
|
const mockAxiosInstance = {
|
||||||
|
get: vi.fn().mockResolvedValue({
|
||||||
|
data: { balance: { credits: 0 } },
|
||||||
|
status: 200
|
||||||
|
}),
|
||||||
|
post: vi.fn().mockResolvedValue({
|
||||||
|
data: { id: 'test-customer-id' },
|
||||||
|
status: 201
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
default: {
|
||||||
|
create: vi.fn().mockReturnValue(mockAxiosInstance),
|
||||||
|
isAxiosError: vi.fn().mockImplementation(() => false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const mockedAxios = vi.mocked(axios)
|
const mockedAxios = vi.mocked(axios)
|
||||||
|
const mockAxiosInstance = mockedAxios.create() as any
|
||||||
// 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
|
// Mock fetch
|
||||||
const mockFetch = vi.fn()
|
const mockFetch = vi.fn()
|
||||||
@@ -122,7 +127,7 @@ describe('useFirebaseAuthStore', () => {
|
|||||||
data: { id: 'test-customer-id' },
|
data: { id: 'test-customer-id' },
|
||||||
status: 201
|
status: 201
|
||||||
})
|
})
|
||||||
mockedAxios.isAxiosError = vi.fn().mockImplementation(() => false) as any
|
;(mockedAxios.isAxiosError as any).mockReturnValue(false)
|
||||||
|
|
||||||
// Mock useFirebaseAuth to return our mock auth object
|
// Mock useFirebaseAuth to return our mock auth object
|
||||||
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)
|
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)
|
||||||
|
|||||||
Reference in New Issue
Block a user