fix: avoid global mock clearing in Navigation tests
- Add explicit next/link mock for consistency - Remove mock.clearAllMocks() from beforeEach/afterEach - Navigation tests now rely on module mocks set at file level - Prevents interference with other test files
This commit is contained in:
@@ -9,6 +9,13 @@ import { describe, it, expect, mock, beforeEach, afterEach } from 'bun:test'
|
|||||||
import { render, screen, waitFor } from '@testing-library/react'
|
import { render, screen, waitFor } from '@testing-library/react'
|
||||||
import Navigation from '@/components/Navigation'
|
import Navigation from '@/components/Navigation'
|
||||||
|
|
||||||
|
// Mock next/link
|
||||||
|
mock.module('next/link', () => ({
|
||||||
|
default: ({ children, href }: { children: React.ReactNode; href: string }) => (
|
||||||
|
<a href={href}>{children}</a>
|
||||||
|
),
|
||||||
|
}))
|
||||||
|
|
||||||
// Mock the SessionProvider
|
// Mock the SessionProvider
|
||||||
mock.module('@/components/SessionProvider', () => ({
|
mock.module('@/components/SessionProvider', () => ({
|
||||||
useSession: mock(() => {}),
|
useSession: mock(() => {}),
|
||||||
@@ -28,8 +35,9 @@ import { useSession } from '@/components/SessionProvider'
|
|||||||
|
|
||||||
describe('Epic 1: Navigation Component', () => {
|
describe('Epic 1: Navigation Component', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mock.clearAllMocks();
|
// Don't clear all mocks as it might affect bun-setup.ts
|
||||||
(global.fetch).mockImplementation(async (url) => {
|
// Set up default fetch mock
|
||||||
|
(global.fetch as any).mockImplementation?.(async (url: any) => {
|
||||||
if (url?.toString().includes('/api/users/')) {
|
if (url?.toString().includes('/api/users/')) {
|
||||||
return new Response(JSON.stringify({ role: 'player' }), {
|
return new Response(JSON.stringify({ role: 'player' }), {
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -41,7 +49,8 @@ describe('Epic 1: Navigation Component', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.clearAllMocks();
|
// Don't clear mocks - let them persist for other test files
|
||||||
|
// Navigation relies on module mocks set up at file level
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders the logo and basic links when not logged in', () => {
|
it('renders the logo and basic links when not logged in', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user