diff --git a/src/components/ProtectedRoute.test.tsx b/src/components/ProtectedRoute.test.tsx index c0a1929..19bb17b 100644 --- a/src/components/ProtectedRoute.test.tsx +++ b/src/components/ProtectedRoute.test.tsx @@ -2,8 +2,8 @@ import { render, screen } from '@testing-library/react' import { MemoryRouter, Routes, Route } from 'react-router-dom' import { describe, it, expect, vi } from 'vitest' -const useAdminAuthMock = vi.fn() -vi.mock('../hooks/useAdminAuth', () => ({ default: () => useAdminAuthMock() })) +const adminAuthMock = vi.fn() +vi.mock('../hooks/useAdminAuth', () => ({ default: () => adminAuthMock() })) import ProtectedRoute from './ProtectedRoute' @@ -22,20 +22,20 @@ function renderWithRoute() { describe('ProtectedRoute', () => { it('renders nothing while loading', () => { - useAdminAuthMock.mockReturnValue({ session: null, loading: true }) + adminAuthMock.mockReturnValue({ session: null, loading: true }) renderWithRoute() expect(screen.queryByText('Products page')).not.toBeInTheDocument() expect(screen.queryByText('Login page')).not.toBeInTheDocument() }) it('redirects to /admin/login when there is no session', () => { - useAdminAuthMock.mockReturnValue({ session: null, loading: false }) + adminAuthMock.mockReturnValue({ session: null, loading: false }) renderWithRoute() expect(screen.getByText('Login page')).toBeInTheDocument() }) it('renders the protected content when there is a session', () => { - useAdminAuthMock.mockReturnValue({ session: { user: { id: 'admin' } }, loading: false }) + adminAuthMock.mockReturnValue({ session: { user: { id: 'admin' } }, loading: false }) renderWithRoute() expect(screen.getByText('Products page')).toBeInTheDocument() })