fix: improve TypeScript types for better IDE code hinting

- Install @types/bun and @types/jsdom for proper type definitions
- Fix mock function typing in test files
- Create jest-dom.d.ts to properly extend Bun's Matchers interface
- Remove MockedFunction imports (not supported in Bun's types)
- Cast global.fetch and useSession mocks to any where needed
- Fix mock.module return types to match expected signatures

This resolves TypeScript errors that were preventing proper code
completion and type checking in IDEs.
This commit is contained in:
2026-04-01 12:44:44 -07:00
parent e8f0fd2538
commit ed43399b24
6 changed files with 48 additions and 33 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, mock, beforeEach, MockedFunction } from 'bun:test'
import { describe, it, expect, mock, beforeEach } from 'bun:test'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import EditTournamentForm from '@/components/EditTournamentForm'
@@ -18,8 +18,8 @@ mock.module('next/link', () => ({
}))
// Mock fetch
const mockFetch = mock(() => {})
global.fetch = mockFetch as MockedFunction<typeof global.fetch>
const mockFetch = mock(async () => new Response())
global.fetch = mockFetch as any
const mockTournament = {
id: 1,
+6 -5
View File
@@ -18,7 +18,7 @@ mock.module('next/link', () => ({
// Mock the SessionProvider
mock.module('@/components/SessionProvider', () => ({
useSession: mock(() => {}),
useSession: mock(() => ({ session: null, loading: false, refreshSession: mock(() => {}) })),
}))
// Mock the auth-client
@@ -29,9 +29,10 @@ mock.module('@/lib/auth-client', () => ({
}))
// Mock fetch for role API call
global.fetch = mock(() => {})
global.fetch = mock(async () => new Response()) as any
import { useSession } from '@/components/SessionProvider'
import { useSession as useSessionOriginal } from '@/components/SessionProvider'
const useSession = useSessionOriginal as any
describe('Epic 1: Navigation Component', () => {
beforeEach(() => {
@@ -131,7 +132,7 @@ describe('Epic 1: Navigation Component', () => {
});
// Mock fetch to return club_admin role
(global.fetch).mockImplementation(async (url) => {
(global.fetch as any).mockImplementation(async (url: any) => {
if (url?.toString().includes('/api/users/admin-123/role')) {
return new Response(JSON.stringify({ role: 'club_admin' }), {
status: 200,
@@ -165,7 +166,7 @@ describe('Epic 1: Navigation Component', () => {
});
// Mock fetch to return player role (already set in beforeEach, but explicit here)
(global.fetch).mockImplementation(async (url) => {
(global.fetch as any).mockImplementation(async (url: any) => {
if (url?.toString().includes('/api/users/')) {
return {
json: () => Promise.resolve({ role: 'player' }),
+9 -9
View File
@@ -1,19 +1,19 @@
import { describe, it, expect, mock, beforeEach, MockedFunction } from 'bun:test'
import { describe, it, expect, mock, beforeEach } from 'bun:test'
import { getSession } from '@/lib/auth-simple'
// Mock next/headers
mock.module('next/headers', () => ({
cookies: mock(() => {}).mockResolvedValue({
get: mock(() => {}).mockReturnValue({ name: 'better-auth.session_token', value: 'test-token' }),
}),
headers: mock(() => {}).mockResolvedValue({
get: mock(() => {}).mockReturnValue(null),
}),
cookies: mock(() => Promise.resolve({
get: mock(() => ({ name: 'better-auth.session_token', value: 'test-token' })),
})),
headers: mock(() => Promise.resolve({
get: mock(() => null),
})),
}))
// Mock fetch
const mockFetch = mock(() => {})
global.fetch = mockFetch as MockedFunction<typeof global.fetch>
const mockFetch = mock(async () => new Response())
global.fetch = mockFetch as any
describe('getSession', () => {
beforeEach(() => {
+12
View File
@@ -0,0 +1,12 @@
/// <reference types="@testing-library/jest-dom" />
import { type expect } from 'bun:test'
import { type TestingLibraryMatchers } from '@testing-library/jest-dom/matchers'
declare module 'bun:test' {
interface Matchers<T = any>
extends TestingLibraryMatchers<
ReturnType<typeof expect.stringContaining>,
T
> {}
}