Files
Creeer-Web/vitest.setup.ts
T

37 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import '@testing-library/jest-dom/vitest';
// jsdom lacks IntersectionObserver; Framer Motion's `whileInView` needs it.
if (typeof window !== 'undefined' && !('IntersectionObserver' in window)) {
class IntersectionObserverStub {
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return [];
}
root = null;
rootMargin = '';
thresholds = [];
}
// @ts-expect-error – installing stub on window
window.IntersectionObserver = IntersectionObserverStub;
global.IntersectionObserver = IntersectionObserverStub;
}
// jsdom lacks matchMedia; usePrefersReducedMotion() calls it in useEffect.
// Note: vitest's jsdom environment pre-defines `matchMedia` as an own property
// set to `undefined`, so `'matchMedia' in window` is true even though it isn't
// a function — guard on typeof instead of `in`.
if (typeof window !== 'undefined' && typeof window.matchMedia !== 'function') {
window.matchMedia = (query: string) => ({
matches: false,
media: query,
onchange: null,
addEventListener: () => {},
removeEventListener: () => {},
addListener: () => {},
removeListener: () => {},
dispatchEvent: () => false,
}) as unknown as MediaQueryList;
}