Compare commits
4 Commits
b90ec08966
...
4e3b25e2fc
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e3b25e2fc | |||
| e4c4333b40 | |||
| 09302fd911 | |||
| 0d9707ea27 |
+1
-1
@@ -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
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
@@ -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 = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user