From e4c4333b407a45358fb9dbac23975ac637d7cbc5 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Wed, 1 Apr 2026 12:20:13 -0700 Subject: [PATCH] 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 --- src/__tests__/Navigation.test.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/__tests__/Navigation.test.tsx b/src/__tests__/Navigation.test.tsx index 34021d5..f5a97d3 100644 --- a/src/__tests__/Navigation.test.tsx +++ b/src/__tests__/Navigation.test.tsx @@ -9,6 +9,13 @@ import { describe, it, expect, mock, beforeEach, afterEach } from 'bun:test' import { render, screen, waitFor } from '@testing-library/react' import Navigation from '@/components/Navigation' +// Mock next/link +mock.module('next/link', () => ({ + default: ({ children, href }: { children: React.ReactNode; href: string }) => ( + {children} + ), +})) + // Mock the SessionProvider mock.module('@/components/SessionProvider', () => ({ useSession: mock(() => {}), @@ -28,8 +35,9 @@ import { useSession } from '@/components/SessionProvider' describe('Epic 1: Navigation Component', () => { beforeEach(() => { - mock.clearAllMocks(); - (global.fetch).mockImplementation(async (url) => { + // Don't clear all mocks as it might affect bun-setup.ts + // Set up default fetch mock + (global.fetch as any).mockImplementation?.(async (url: any) => { if (url?.toString().includes('/api/users/')) { return new Response(JSON.stringify({ role: 'player' }), { status: 200, @@ -41,7 +49,8 @@ describe('Epic 1: Navigation Component', () => { }) 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', () => {