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:
@@ -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' }),
|
||||
|
||||
Reference in New Issue
Block a user