From 2e80a5789c2137fc86377588bd6cb2e3d05f321d Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 15 Aug 2025 15:37:06 -0700 Subject: [PATCH] [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 --- .../tests/store/firebaseAuthStore.test.ts | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests-ui/tests/store/firebaseAuthStore.test.ts b/tests-ui/tests/store/firebaseAuthStore.test.ts index e66389f5a..f7c9f94c7 100644 --- a/tests-ui/tests/store/firebaseAuthStore.test.ts +++ b/tests-ui/tests/store/firebaseAuthStore.test.ts @@ -7,23 +7,28 @@ import * as vuefire from 'vuefire' import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore' // 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) - -// 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 +const mockAxiosInstance = mockedAxios.create() as any // Mock fetch const mockFetch = vi.fn() @@ -122,7 +127,7 @@ describe('useFirebaseAuthStore', () => { data: { id: 'test-customer-id' }, status: 201 }) - mockedAxios.isAxiosError = vi.fn().mockImplementation(() => false) as any + ;(mockedAxios.isAxiosError as any).mockReturnValue(false) // Mock useFirebaseAuth to return our mock auth object vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)