From 5a7e0f2195e86b6f54f8a1b8098fb5823611a916 Mon Sep 17 00:00:00 2001 From: belviskhoremk Date: Wed, 12 Aug 2026 10:59:40 +0200 Subject: [PATCH] fix: rename mock variable to avoid ESLint react-hooks/rules-of-hooks false positive Renamed useAdminAuthMock to adminAuthMock in ProtectedRoute.test.tsx to prevent ESLint from flagging it as an invalid hook call. The 'use' prefix naming heuristic was causing a react-hooks/rules-of-hooks rule violation, though it was not actually a hook call context. This change maintains all test behavior while passing lint. --- src/components/ProtectedRoute.test.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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() })