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:
@@ -33,15 +33,15 @@ describe('useActiveClub', () => {
|
||||
status: 'authenticated',
|
||||
});
|
||||
|
||||
vi.mocked(localStorage.getItem).mockImplementation((key: string) => {
|
||||
(localStorage.getItem as any).mockImplementation((key: string) => {
|
||||
return localStorageData[key] || null;
|
||||
});
|
||||
|
||||
vi.mocked(localStorage.setItem).mockImplementation((key: string, value: string) => {
|
||||
(localStorage.setItem as any).mockImplementation((key: string, value: string) => {
|
||||
localStorageData[key] = value;
|
||||
});
|
||||
|
||||
vi.mocked(localStorage.clear).mockImplementation(() => {
|
||||
(localStorage.clear as any).mockImplementation(() => {
|
||||
localStorageData = {};
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user