import '@testing-library/jest-dom'; import { cleanup } from '@testing-library/react'; import { afterEach, vi } from 'vitest'; // Cleanup after each test afterEach(() => { cleanup(); }); // Mock window.matchMedia Object.defineProperty(window, 'matchMedia', { writable: true, value: vi.fn().mockImplementation(query => ({ matches: false, media: query, onchange: null, addListener: vi.fn(), // deprecated removeListener: vi.fn(), // deprecated addEventListener: vi.fn(), removeEventListener: vi.fn(), dispatchEvent: vi.fn(), })), }); // Mock IntersectionObserver global.IntersectionObserver = vi.fn().mockImplementation(() => ({ observe: vi.fn(), unobserve: vi.fn(), disconnect: vi.fn(), })); // Mock fetch globally global.fetch = vi.fn(); // Reset mocks before each test beforeEach(() => { vi.clearAllMocks(); // Default fetch mock (global.fetch as any).mockResolvedValue({ ok: true, json: async () => ({}), text: async () => '', status: 200, statusText: 'OK', }); }); // Mock Google Identity Services (global as any).google = { accounts: { id: { initialize: vi.fn(), renderButton: vi.fn(), prompt: vi.fn(), disableAutoSelect: vi.fn(), storeCredential: vi.fn(), cancel: vi.fn(), onGoogleLibraryLoad: vi.fn(), revoke: vi.fn(), }, oauth2: { initTokenClient: vi.fn(), initCodeClient: vi.fn(), hasGrantedAnyScope: vi.fn(), hasGrantedAllScopes: vi.fn(), revoke: vi.fn(), }, }, }; // Mock console methods to reduce test noise const originalError = console.error; const originalWarn = console.warn; beforeAll(() => { console.error = vi.fn(); console.warn = vi.fn(); }); afterAll(() => { console.error = originalError; console.warn = originalWarn; });