1 import '@testing-library/jest-dom';
2 import { cleanup } from '@testing-library/react';
3 import { vi } from 'vitest';
5 import '@proton/testing/lib/vitest/mockMatchMedia';
6 import '@proton/testing/lib/vitest/mockUnleash';
9 global.IS_REACT_ACT_ENVIRONMENT = true;
11 afterEach(cleanup); // TODO double check if needed; see https://github.com/vitest-dev/vitest/issues/1430
12 // Silence warnings on expect to throw https://github.com/testing-library/react-testing-library/issues/157
13 // console.error = () => {};
14 // console.warn = () => {};
16 window.ResizeObserver = vi.fn().mockImplementation(() => ({
22 // JSDom does not include a full implementation of webcrypto
23 // const crypto = require('crypto').webcrypto;
24 // global.crypto.subtle = crypto.subtle;
26 // Do not start crypto worker pool, let the single tests setup/mock the CryptoProxy as needed
27 vi.mock('@proton/shared/lib/helpers/setupCryptoWorker', () => ({
29 loadCryptoWorker: vi.fn(),
32 // Globally mocked @proton/components modules
33 vi.mock('@proton/components/hooks/useEventManager.ts', () => {
34 const subscribe = vi.fn();
37 const start = vi.fn();
39 const result = () => {
40 return { subscribe, call, stop, start };
43 result.subscribe = subscribe;
48 return { default: result };
51 // Globally mocked upload helper (standard requests are mocked through context)
52 vi.mock('./src/app/helpers/upload');
55 global.MutationObserver = class {
56 disconnect() {} // eslint-disable-line
57 observe() {} // eslint-disable-line
60 // Mock backdrop container because it's always rendered, and it's rendered in a portal which causes issues with the hook renderer
61 vi.mock('@proton/components/components/modalTwo/BackdropContainer', () => ({
66 // Silence JDOM warnings triggered by emoji-mart
68 HTMLCanvasElement.prototype.getContext = vi.fn();
70 vi.mock('@proton/shared/lib/i18n/dateFnLocales', () => ({
72 enUSLocale: { code: 'en-US' },
75 vi.mock('@proton/shared/lib/pow/wasmWorkerWrapper.ts', () => ({
79 vi.mock('@proton/shared/lib/pow/pbkdfWorkerWrapper.ts', () => ({