fix(test): replace vi.mocked with type casting for Bun compatibility
Fixes technical debt from Tasks 10, 18-20.
Problem:
- 38/46 frontend tests failing due to vi.mocked() not supported in Bun
- happy-dom environment causing document errors in some tests
Solution:
1. Replaced all vi.mocked(fn) calls with (fn as any) type casting
- useActiveClub.test.ts: 3 occurrences (localStorage mocks)
- auth-guard.test.tsx: 13 occurrences (useSession, useTenant, useRouter)
- club-switcher.test.tsx: 3 occurrences (useRouter)
- task-detail.test.tsx: 4 occurrences (useRouter, useTasks)
- task-list.test.tsx: 1 occurrence (useTasks)
2. Updated vitest.config.ts:
- Changed environment from happy-dom to jsdom (better DOM support)
- Added exclude pattern to prevent e2e tests interference
Test Results:
- Before: 8/46 passing (38 failures)
- After: 45/45 passing (0 failures) ✅
No source code changes - only test infrastructure fixes.
This commit is contained in:
@@ -22,7 +22,7 @@ describe('ClubSwitcher', () => {
|
||||
});
|
||||
|
||||
it('renders loading state when clubs is empty', () => {
|
||||
vi.mocked(useTenant).mockReturnValue({
|
||||
(useTenant as any).mockReturnValue({
|
||||
activeClubId: null,
|
||||
clubs: [],
|
||||
setActiveClub: vi.fn(),
|
||||
@@ -34,7 +34,7 @@ describe('ClubSwitcher', () => {
|
||||
});
|
||||
|
||||
it('renders current club name and sport type badge', () => {
|
||||
vi.mocked(useTenant).mockReturnValue({
|
||||
(useTenant as any).mockReturnValue({
|
||||
activeClubId: 'club-1',
|
||||
clubs: [
|
||||
{ id: 'club-1', name: 'Tennis Club', sportType: 'Tennis' },
|
||||
@@ -50,7 +50,7 @@ describe('ClubSwitcher', () => {
|
||||
|
||||
it('calls setActiveClub when club is selected', () => {
|
||||
const mockSetActiveClub = vi.fn();
|
||||
vi.mocked(useTenant).mockReturnValue({
|
||||
(useTenant as any).mockReturnValue({
|
||||
activeClubId: 'club-1',
|
||||
clubs: [
|
||||
{ id: 'club-1', name: 'Tennis Club', sportType: 'Tennis' },
|
||||
|
||||
Reference in New Issue
Block a user