buster/apps/web-tss/vitest.setup.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-08-12 11:28:36 +08:00
// Learn more: https://github.com/testing-library/jest-dom
//import '@testing-library/jest-dom';
2025-08-13 03:21:24 +08:00
import { vi } from 'vitest';
2025-08-12 11:28:36 +08:00
// Mock react-hotkeys-hook
2025-08-13 03:21:24 +08:00
vi.mock('react-hotkeys-hook', () => ({
2025-08-13 11:54:24 +08:00
useHotkeys: vi.fn(),
2025-08-12 11:28:36 +08:00
}));
2025-08-13 03:21:24 +08:00
vi.mock('react-markdown', () => ({
2025-08-12 11:28:36 +08:00
__esModule: true,
2025-08-13 11:54:24 +08:00
default: vi.fn(),
2025-08-12 11:28:36 +08:00
}));
2025-08-13 03:21:24 +08:00
vi.mock('remark-gfm', () => ({
2025-08-12 11:28:36 +08:00
__esModule: true,
2025-08-13 11:54:24 +08:00
default: vi.fn(),
2025-08-12 11:28:36 +08:00
}));
// Mock Supabase client to prevent environment variable errors in tests
2025-08-13 03:21:24 +08:00
vi.mock('@/lib/supabase/client', () => {
2025-08-12 11:28:36 +08:00
const mockClient = {
auth: {
refreshSession: vi.fn().mockResolvedValue({
data: {
session: {
2025-08-13 03:21:24 +08:00
access_token: 'mock-token',
2025-08-13 11:54:24 +08:00
expires_at: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
},
2025-08-12 11:28:36 +08:00
},
2025-08-13 11:54:24 +08:00
error: null,
2025-08-12 11:28:36 +08:00
}),
getUser: vi.fn().mockResolvedValue({
data: { user: null },
2025-08-13 11:54:24 +08:00
error: null,
2025-08-12 11:28:36 +08:00
}),
getSession: vi.fn().mockResolvedValue({
data: {
session: {
2025-08-13 03:21:24 +08:00
access_token: 'mock-token',
2025-08-13 11:54:24 +08:00
expires_at: Math.floor(Date.now() / 1000) + 3600,
},
2025-08-12 11:28:36 +08:00
},
2025-08-13 11:54:24 +08:00
error: null,
2025-08-12 11:28:36 +08:00
}),
onAuthStateChange: vi.fn().mockReturnValue({
2025-08-13 11:54:24 +08:00
data: { subscription: { unsubscribe: vi.fn() } },
}),
},
2025-08-12 11:28:36 +08:00
};
return {
createBrowserClient: vi.fn(() => mockClient),
2025-08-13 11:54:24 +08:00
getBrowserClient: vi.fn(() => mockClient),
2025-08-12 11:28:36 +08:00
};
});