add tests
This commit is contained in:
54
apps/website/tests/setup/vitest.setup.ts
Normal file
54
apps/website/tests/setup/vitest.setup.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Vitest Setup for Website Components
|
||||
*
|
||||
* This file sets up the testing environment for website component tests.
|
||||
* It mocks external dependencies and provides custom matchers.
|
||||
*/
|
||||
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
import { vi } from 'vitest';
|
||||
|
||||
// Mock Next.js navigation
|
||||
vi.mock('next/navigation', () => ({
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
back: vi.fn(),
|
||||
forward: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
}),
|
||||
usePathname: () => vi.fn(),
|
||||
useSearchParams: () => vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock Next.js headers
|
||||
vi.mock('next/headers', () => ({
|
||||
headers: () => ({
|
||||
get: vi.fn(),
|
||||
set: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock Next.js cookies
|
||||
vi.mock('next/cookies', () => ({
|
||||
cookies: () => ({
|
||||
get: vi.fn(),
|
||||
set: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock React hooks
|
||||
vi.mock('react', async () => {
|
||||
const actual = await vi.importActual('react');
|
||||
return {
|
||||
...actual,
|
||||
useTransition: () => [false, vi.fn()],
|
||||
useOptimistic: (initialState: any) => [initialState, vi.fn()],
|
||||
};
|
||||
});
|
||||
|
||||
// Set environment variables
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL = 'http://localhost:3001';
|
||||
process.env.API_BASE_URL = 'http://localhost:3001';
|
||||
Reference in New Issue
Block a user