import '@testing-library/jest-dom' import matchers from '@testing-library/jest-dom/matchers'; import { expect, beforeAll } from 'vitest'; // Vitest 0.33 ships a localStorage stub that omits clear() — replace with a // full in-memory Storage implementation so tests can call localStorage.clear() const makeStorage = () => { const store: Record = {}; return { getItem: (key: string) => Object.prototype.hasOwnProperty.call(store, key) ? store[key] : null, setItem: (key: string, value: string) => { store[key] = String(value); }, removeItem: (key: string) => { delete store[key]; }, clear: () => { for (const k in store) delete store[k]; }, key: (index: number) => Object.keys(store)[index] ?? null, get length() { return Object.keys(store).length; }, }; }; if (typeof window !== 'undefined') { const localStorageMock = makeStorage(); const sessionStorageMock = makeStorage(); Object.defineProperty(window, 'localStorage', { value: localStorageMock, writable: true }); Object.defineProperty(window, 'sessionStorage', { value: sessionStorageMock, writable: true }); } expect.extend(matchers); // Mock native element methods for testing // JSDOM doesn't support HTMLDialogElement methods yet beforeAll(() => { if (typeof HTMLDialogElement === 'undefined') { // HTMLDialogElement not available at all in this environment global.HTMLDialogElement = class HTMLDialogElement extends HTMLElement { open = false; showModal() { this.open = true; this.setAttribute('open', ''); } show() { this.open = true; this.setAttribute('open', ''); } close() { this.open = false; this.removeAttribute('open'); } } as unknown as typeof window.HTMLDialogElement; } else { // HTMLDialogElement exists but methods aren't implemented HTMLDialogElement.prototype.showModal = HTMLDialogElement.prototype.showModal || function showModal(this: HTMLDialogElement) { // eslint-disable-next-line @typescript-eslint/no-explicit-any (this as any).open = true; this.setAttribute('open', ''); }; HTMLDialogElement.prototype.show = HTMLDialogElement.prototype.show || function show(this: HTMLDialogElement) { // eslint-disable-next-line @typescript-eslint/no-explicit-any (this as any).open = true; this.setAttribute('open', ''); }; HTMLDialogElement.prototype.close = HTMLDialogElement.prototype.close || function close(this: HTMLDialogElement) { // eslint-disable-next-line @typescript-eslint/no-explicit-any (this as any).open = false; this.removeAttribute('open'); }; } });