4 Commits

Author SHA1 Message Date
david 4e3b25e2fc fix: avoid global mock clearing in EditTournamentForm tests
Pull Request / unit-tests (pull_request) Failing after 59s
Pull Request / acceptance-tests (pull_request) Has been skipped
Pull Request / analyze-bump-type (pull_request) Has been skipped
Replace mock.clearAllMocks() with mockFetch.mockClear() to only
clear the specific fetch mock without affecting global module mocks
used by other test files.
2026-04-01 12:20:16 -07:00
david e4c4333b40 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
2026-04-01 12:20:13 -07:00
david 09302fd911 fix: add DOM cleanup to bun-setup.ts
Add afterEach hook to clear document.body.innerHTML between tests.
This prevents test pollution where elements from previous tests
interfere with subsequent test queries.
2026-04-01 12:20:10 -07:00
david 0d9707ea27 fix: disable test isolation in bunfig.toml
Comment out isolation = true as it was causing test execution issues.
Tests run correctly without isolation when DOM cleanup is properly managed.
2026-04-01 12:20:06 -07:00
4 changed files with 30 additions and 12 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[test] [test]
preload = ["./src/__tests__/bun-setup.ts"] preload = ["./src/__tests__/bun-setup.ts"]
exclude = ["e2e/**", "**/e2e/**"] exclude = ["e2e/**", "**/e2e/**"]
isolation = true # isolation = true
+2 -1
View File
@@ -40,7 +40,8 @@ const mockTournament = {
describe('EditTournamentForm', () => { describe('EditTournamentForm', () => {
beforeEach(() => { beforeEach(() => {
mock.clearAllMocks() // Only clear the specific mocks we create, not global module mocks
mockFetch.mockClear()
}) })
it('renders form with initial values', () => { it('renders form with initial values', () => {
+12 -3
View File
@@ -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', () => {
+15 -7
View File
@@ -1,7 +1,7 @@
// Setup file for Bun test runner to provide DOM environment // Setup file for Bun test runner to provide DOM environment
import { JSDOM } from 'jsdom'; import { JSDOM } from 'jsdom';
import '@testing-library/jest-dom';
import { act } from '@testing-library/react'; console.log('Loading bun-setup.ts...');
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', { const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
url: 'http://localhost', url: 'http://localhost',
@@ -12,8 +12,16 @@ const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
(global as any).document = dom.window.document; (global as any).document = dom.window.document;
(global as any).navigator = dom.window.navigator; (global as any).navigator = dom.window.navigator;
// Extend global act to handle async operations console.log('bun-setup.ts loaded - document:', typeof (global as any).document);
const originalAct = act; console.log('document.body:', (global as any).document?.body);
(global as any).act = async (callback: () => Promise<void> | void) => {
return originalAct(callback); // Import jest-dom matchers after setting up the DOM
}; import '@testing-library/jest-dom';
// Clear document body after each test
import { afterEach } from 'bun:test';
afterEach(() => {
if (global.document?.body) {
global.document.body.innerHTML = '';
}
});