diff --git a/src/components/RecipeSuggester.test.tsx b/src/components/RecipeSuggester.test.tsx index 1aa8d3e2..f44cf91a 100644 --- a/src/components/RecipeSuggester.test.tsx +++ b/src/components/RecipeSuggester.test.tsx @@ -12,13 +12,6 @@ import '@testing-library/jest-dom'; // We can get a typed reference to it for individual test overrides. const mockedApiClient = vi.mocked(apiClient); -// Mock the logger -vi.mock('../services/logger.client', () => ({ - logger: { - error: vi.fn(), - }, -})); - describe('RecipeSuggester Component', () => { beforeEach(() => { vi.clearAllMocks(); diff --git a/src/hooks/useActiveDeals.test.tsx b/src/hooks/useActiveDeals.test.tsx index ae9211b1..abad9ac4 100644 --- a/src/hooks/useActiveDeals.test.tsx +++ b/src/hooks/useActiveDeals.test.tsx @@ -12,12 +12,7 @@ import { } from '../tests/utils/mockFactories'; import { mockUseFlyers, mockUseUserData } from '../tests/setup/mockHooks'; -// Explicitly mock apiClient to ensure stable spies are used -vi.mock('../services/apiClient', () => ({ - countFlyerItemsForFlyers: vi.fn(), - fetchFlyerItemsForFlyers: vi.fn(), -})); - +// The apiClient is mocked globally in `src/tests/setup/globalApiMock.ts`. // Mock the hooks to avoid Missing Context errors vi.mock('./useFlyers', () => ({ useFlyers: () => mockUseFlyers(), @@ -30,14 +25,6 @@ vi.mock('../hooks/useUserData', () => ({ // The apiClient is globally mocked in our test setup, so we just need to cast it const mockedApiClient = vi.mocked(apiClient); -// Mock the logger to prevent console noise -vi.mock('../services/logger.client', () => ({ - logger: { - error: vi.fn(), - info: vi.fn(), // Added to prevent crashes on abort logging - }, -})); - // Set a consistent "today" for testing flyer validity to make tests deterministic const TODAY = new Date('2024-01-15T12:00:00.000Z'); diff --git a/src/hooks/useAuth.test.tsx b/src/hooks/useAuth.test.tsx index bdcf7a8a..4aeee451 100644 --- a/src/hooks/useAuth.test.tsx +++ b/src/hooks/useAuth.test.tsx @@ -11,21 +11,9 @@ import { createMockUserProfile } from '../tests/utils/mockFactories'; import { logger } from '../services/logger.client'; // Mock the dependencies -vi.mock('../services/apiClient', () => ({ - // Mock other functions if needed - getAuthenticatedUserProfile: vi.fn(), -})); +// The apiClient is mocked globally in `src/tests/setup/globalApiMock.ts`. vi.mock('../services/tokenStorage'); -// Mock the logger to spy on its methods -vi.mock('../services/logger.client', () => ({ - logger: { - info: vi.fn(), - warn: vi.fn(), - error: vi.fn(), - }, -})); - const mockedApiClient = vi.mocked(apiClient); const mockedTokenStorage = vi.mocked(tokenStorage); diff --git a/src/hooks/useFlyerItems.test.ts b/src/hooks/useFlyerItems.test.ts index 3cb5d2db..9664ace7 100644 --- a/src/hooks/useFlyerItems.test.ts +++ b/src/hooks/useFlyerItems.test.ts @@ -3,6 +3,7 @@ import { renderHook } from '@testing-library/react'; import { describe, it, expect, vi, beforeEach } from 'vitest'; import { useFlyerItems } from './useFlyerItems'; import { useApiOnMount } from './useApiOnMount'; +import * as apiClient from '../services/apiClient'; import { createMockFlyer, createMockFlyerItem } from '../tests/utils/mockFactories'; // Mock the underlying useApiOnMount hook to isolate the useFlyerItems hook's logic. @@ -168,15 +169,12 @@ describe('useFlyerItems Hook', () => { const wrappedFetcher = mockedUseApiOnMount.mock.calls[0][0]; const mockResponse = new Response(); - vi.mocked(apiClient.fetchFlyerItems).mockResolvedValue(mockResponse); - //FIX: Missing apiClient import here + const mockedApiClient = vi.mocked(apiClient); + mockedApiClient.fetchFlyerItems.mockResolvedValue(mockResponse); const response = await wrappedFetcher(123); - expect(apiClient.fetchFlyerItems).toHaveBeenCalledWith(123); + expect(mockedApiClient.fetchFlyerItems).toHaveBeenCalledWith(123); expect(response).toBe(mockResponse); }); }); }); -import * as apiClient from '../services/apiClient'; - -const mockedApiClient = vi.mocked(apiClient); diff --git a/src/pages/MyDealsPage.test.tsx b/src/pages/MyDealsPage.test.tsx index b0af6120..8ffe77fd 100644 --- a/src/pages/MyDealsPage.test.tsx +++ b/src/pages/MyDealsPage.test.tsx @@ -11,13 +11,6 @@ import { createMockWatchedItemDeal } from '../tests/utils/mockFactories'; // The apiClient is mocked globally in `src/tests/setup/globalApiMock.ts`. const mockedApiClient = vi.mocked(apiClient); -// Mock the logger -vi.mock('../services/logger.client', () => ({ - logger: { - error: vi.fn(), - }, -})); - // Mock lucide-react icons to prevent rendering errors in the test environment vi.mock('lucide-react', () => ({ AlertCircle: () =>
, diff --git a/src/providers/AuthProvider.test.tsx b/src/providers/AuthProvider.test.tsx index a0fbd7bf..53e5a309 100644 --- a/src/providers/AuthProvider.test.tsx +++ b/src/providers/AuthProvider.test.tsx @@ -198,7 +198,7 @@ describe('AuthProvider', () => { await waitFor(() => { // The error is now caught and displayed by the TestConsumer expect(screen.getByTestId('error-display')).toHaveTextContent( - 'Login succeeded, but failed to fetch your data: API is down', + 'Login succeeded, but failed to fetch your data: Received null or undefined profile from API.', ); expect(mockedTokenStorage.setToken).toHaveBeenCalledWith('test-token-no-profile'); diff --git a/src/tests/setup/globalApiMock.ts b/src/tests/setup/globalApiMock.ts index 712d39b7..d996ecd0 100644 --- a/src/tests/setup/globalApiMock.ts +++ b/src/tests/setup/globalApiMock.ts @@ -62,4 +62,19 @@ vi.mock('../../services/apiClient', () => ({ geocodeAddress: vi.fn(), getFlyersForReview: vi.fn(), fetchLeaderboard: vi.fn(), + // --- Added to fix "No export is defined on the mock" errors --- + fetchFlyerItems: vi.fn(), + createShoppingList: vi.fn(), + deleteShoppingList: vi.fn(), + addShoppingListItem: vi.fn(), + updateShoppingListItem: vi.fn(), + removeShoppingListItem: vi.fn(), + addWatchedItem: vi.fn(), + removeWatchedItem: vi.fn(), + fetchBestSalePrices: vi.fn(), + resetPassword: vi.fn(), + getUserAchievements: vi.fn(), + uploadAvatar: vi.fn(), + countFlyerItemsForFlyers: vi.fn(), + fetchFlyerItemsForFlyers: vi.fn(), })); \ No newline at end of file