45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
// Copyright (c) 2025 Patrick Motsch
|
|
// All rights reserved.
|
|
//
|
|
// Vitest global setup: jest-dom matchers + jsdom polyfills required by some
|
|
// of our components (ResizeObserver, matchMedia, scrollIntoView).
|
|
|
|
import '@testing-library/jest-dom/vitest';
|
|
import { afterEach } from 'vitest';
|
|
import { cleanup } from '@testing-library/react';
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
});
|
|
|
|
class _ResizeObserverPolyfill {
|
|
observe(): void {}
|
|
unobserve(): void {}
|
|
disconnect(): void {}
|
|
}
|
|
|
|
if (!('ResizeObserver' in globalThis)) {
|
|
(globalThis as unknown as { ResizeObserver: typeof _ResizeObserverPolyfill }).ResizeObserver =
|
|
_ResizeObserverPolyfill;
|
|
}
|
|
|
|
if (!('matchMedia' in window)) {
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: (query: string) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: () => {},
|
|
removeListener: () => {},
|
|
addEventListener: () => {},
|
|
removeEventListener: () => {},
|
|
dispatchEvent: () => false,
|
|
}),
|
|
});
|
|
}
|
|
|
|
if (!('scrollIntoView' in HTMLElement.prototype)) {
|
|
(HTMLElement.prototype as unknown as { scrollIntoView: () => void }).scrollIntoView =
|
|
function (): void {};
|
|
}
|