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.
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user