Files
stack/apps/web/vitest.setup.ts
Jason Woltje c23ebca648
Some checks failed
ci/woodpecker/push/orchestrator Pipeline was successful
ci/woodpecker/push/web Pipeline failed
ci/woodpecker/push/api Pipeline was successful
fix(ci): resolve pipeline #516 audit and test failures (#429)
Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
2026-02-21 20:11:58 +00:00

57 lines
1.5 KiB
TypeScript

import { cleanup } from "@testing-library/react";
import { afterEach, expect } from "vitest";
import * as matchers from "@testing-library/jest-dom/matchers";
// Extend Vitest's expect with jest-dom matchers
expect.extend(matchers);
// Cleanup after each test to prevent test pollution
afterEach(() => {
cleanup();
});
// Mock window.matchMedia for tests that might use it
Object.defineProperty(window, "matchMedia", {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
}),
});
// Ensure localStorage exists with a full Storage API for tests.
// Avoid touching the built-in accessor (which emits warnings in Node).
let storageStore: Record<string, string> = {};
const storageMock: Storage = {
getItem: (key: string): string | null => storageStore[key] ?? null,
setItem: (key: string, value: string): void => {
storageStore[key] = value;
},
removeItem: (key: string): void => {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete storageStore[key];
},
clear: (): void => {
storageStore = {};
},
get length(): number {
return Object.keys(storageStore).length;
},
key: (index: number): string | null => {
const keys = Object.keys(storageStore);
return keys[index] ?? null;
},
};
Object.defineProperty(window, "localStorage", {
value: storageMock,
writable: true,
configurable: true,
});