riseup-squad18/MEDICONNECT 2/vitest.setup.ts

64 lines
1.7 KiB
TypeScript

// vitest.setup.ts - configura ambiente antes dos testes
class MemoryStorage implements Storage {
private store: Record<string, string> = {};
get length() {
return Object.keys(this.store).length;
}
clear(): void {
this.store = {};
}
getItem(key: string): string | null {
return this.store[key] ?? null;
}
key(index: number): string | null {
return Object.keys(this.store)[index] ?? null;
}
removeItem(key: string): void {
delete this.store[key];
}
setItem(key: string, value: string): void {
this.store[key] = value;
}
}
if (typeof window !== "undefined") {
// Substituir localStorage apenas se não existir (jsdom fornece, mas podemos garantir limpeza)
Object.defineProperty(window, "localStorage", { value: new MemoryStorage() });
}
// Garantir documentElement para manipulação de classes
if (typeof document !== "undefined") {
document.documentElement.className = "";
document.documentElement.style.fontSize = "";
}
// Neutraliza bibliotecas que podem injetar wrappers ou side-effects no React durante testes
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - vi está disponível em runtime de testes
if (typeof vi !== "undefined") {
// Mock de ícones
vi.mock("lucide-react", () => {
const Icon = (p: any) => {
return {
$$typeof: Symbol.for("react.element"),
type: "svg",
key: null,
ref: null,
props: { ...p },
_owner: null,
};
};
return {
Accessibility: Icon,
Plus: Icon,
Minus: Icon,
X: Icon,
Volume2: Icon,
Moon: Icon,
Sun: Icon,
};
});
vi.mock("@axe-core/react", () => ({ default: () => {} }));
}