68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import '@testing-library/jest-dom';
|
|
import { vi } from 'vitest';
|
|
|
|
class LocalStorageMock {
|
|
private store: Record<string, string> = {};
|
|
|
|
clear() {
|
|
this.store = {};
|
|
}
|
|
|
|
getItem(key: string) {
|
|
return this.store[key] || null;
|
|
}
|
|
|
|
setItem(key: string, value: string) {
|
|
this.store[key] = String(value);
|
|
}
|
|
|
|
removeItem(key: string) {
|
|
delete this.store[key];
|
|
}
|
|
|
|
get length() {
|
|
return Object.keys(this.store).length;
|
|
}
|
|
|
|
key(index: number) {
|
|
return Object.keys(this.store)[index] || null;
|
|
}
|
|
}
|
|
|
|
const localStorageMock = new LocalStorageMock();
|
|
Object.defineProperty(window, 'localStorage', {
|
|
value: localStorageMock,
|
|
writable: true,
|
|
});
|
|
|
|
// Mock IntersectionObserver for framer-motion/motion viewport triggers
|
|
class IntersectionObserverMock {
|
|
readonly root: Element | null = null;
|
|
readonly rootMargin: string = '';
|
|
readonly thresholds: ReadonlyArray<number> = [];
|
|
constructor(callback: any, options?: any) {}
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
takeRecords() { return []; }
|
|
}
|
|
Object.defineProperty(window, 'IntersectionObserver', {
|
|
value: IntersectionObserverMock,
|
|
writable: true,
|
|
});
|
|
|
|
// Mock matchMedia if needed
|
|
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(),
|
|
})),
|
|
});
|