xtablo-source/apps/main/src/setupTests.ts

45 lines
1 KiB
TypeScript
Raw Normal View History

2025-04-08 07:43:51 +00:00
import "@testing-library/jest-dom";
import { cleanup } from "@testing-library/react";
import { vi } from "vitest";
2025-10-28 21:23:50 +00:00
import "./i18n.test";
2025-04-08 07:43:51 +00:00
// Cleanup after each test case
afterEach(() => {
cleanup();
});
2025-10-28 21:23:50 +00:00
// 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();
}
2025-10-28 21:23:50 +00:00
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(),
})),
});
}