xtablo-source/apps/main/src/setupTests.ts
2026-04-22 22:13:30 +02:00

44 lines
1 KiB
TypeScript

import "@testing-library/jest-dom";
import { cleanup } from "@testing-library/react";
import { vi } from "vitest";
import "./i18n.test";
// Cleanup after each test case
afterEach(() => {
cleanup();
});
// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
observe() {
// Mock implementation
}
unobserve() {
// Mock implementation
}
disconnect() {
// Mock implementation
}
};
// Mock scroll APIs for DOM-oriented tests without breaking node-environment suites.
if (typeof Element !== "undefined") {
Element.prototype.scrollIntoView = vi.fn();
Element.prototype.scrollTo = vi.fn();
}
if (typeof window !== "undefined") {
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(),
})),
});
}