// Configuration globale pour les tests Jest // Mock pour les modules WASM (défini dans jest.config.js si nécessaire) // Mock pour les variables d'environnement process.env.VITE_JWT_SECRET_KEY = 'test-secret-key'; // Polyfills Node pour Web APIs utilisées dans les tests import { TextEncoder, TextDecoder } from 'util'; // @ts-ignore if (!global.TextEncoder) { // @ts-ignore global.TextEncoder = TextEncoder as any; } // @ts-ignore if (!global.TextDecoder) { // @ts-ignore global.TextDecoder = TextDecoder as any; } // Mock pour les APIs Web // @ts-ignore if (!global.crypto) { // @ts-ignore global.crypto = {}; } // @ts-ignore if (!global.crypto.subtle) { // @ts-ignore global.crypto.subtle = { digest: async () => new ArrayBuffer(32) } as any; } // Mocks réseau // @ts-ignore global.fetch = jest.fn(); // Mock pour les WebSockets // @ts-ignore global.WebSocket = jest.fn().mockImplementation(() => ({ send: jest.fn(), close: jest.fn(), addEventListener: jest.fn(), removeEventListener: jest.fn(), readyState: 1 })); // Mock pour localStorage const localStorageMock = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn(), clear: jest.fn(), }; // @ts-ignore global.localStorage = localStorageMock; // Mock pour sessionStorage const sessionStorageMock = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn(), clear: jest.fn(), }; // @ts-ignore global.sessionStorage = sessionStorageMock; // Configuration des timeouts jest.setTimeout(10000); // Nettoyage après chaque test afterEach(() => { jest.clearAllMocks(); localStorageMock.clear(); sessionStorageMock.clear(); });