62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import '@testing-library/jest-dom';
|
|
import { vi } from 'vitest';
|
|
|
|
const originalConsoleError = console.error;
|
|
const originalConsoleWarn = console.warn;
|
|
const suppressedConsolePatterns = [
|
|
/React does not recognize the `.*` prop on a DOM element/i,
|
|
/Unknown event handler property `onPress`/i,
|
|
/non-boolean attribute/i,
|
|
/not wrapped in act/i,
|
|
/Lightbox photo load failed/i,
|
|
];
|
|
|
|
const shouldSuppressConsole = (message?: unknown) =>
|
|
typeof message === 'string' && suppressedConsolePatterns.some((pattern) => pattern.test(message));
|
|
|
|
console.error = (...args: unknown[]) => {
|
|
if (shouldSuppressConsole(args[0])) return;
|
|
originalConsoleError(...args);
|
|
};
|
|
|
|
console.warn = (...args: unknown[]) => {
|
|
if (shouldSuppressConsole(args[0])) return;
|
|
originalConsoleWarn(...args);
|
|
};
|
|
|
|
vi.mock('react-i18next', async () => {
|
|
const actual = await vi.importActual<typeof import('react-i18next')>('react-i18next');
|
|
return {
|
|
...actual,
|
|
useTranslation: () => ({
|
|
t: (key: string, options?: Record<string, unknown>) => {
|
|
if (options && typeof options.defaultValue === 'string') {
|
|
return options.defaultValue;
|
|
}
|
|
return key;
|
|
},
|
|
i18n: {
|
|
language: 'de',
|
|
changeLanguage: vi.fn(),
|
|
},
|
|
}),
|
|
Trans: ({ children }: { children: React.ReactNode }) => children,
|
|
};
|
|
});
|
|
|
|
if (typeof window !== 'undefined' && !window.matchMedia) {
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: (query: string) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: vi.fn(),
|
|
removeListener: vi.fn(),
|
|
addEventListener: vi.fn(),
|
|
removeEventListener: vi.fn(),
|
|
dispatchEvent: vi.fn(),
|
|
}),
|
|
});
|
|
}
|