forked from Qortal/q-blog
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
// tests/setup.ts — registers matchers & MSW
|
|
import '@testing-library/jest-dom/vitest';
|
|
import { afterAll, afterEach, beforeAll, expect } from 'vitest';
|
|
import { toHaveNoViolations } from 'jest-axe';
|
|
import { server } from './msw/server';
|
|
|
|
expect.extend(toHaveNoViolations);
|
|
|
|
beforeAll(() => server.listen({ onUnhandledRequest: 'bypass' }));
|
|
afterEach(() => server.resetHandlers());
|
|
afterAll(() => server.close());
|
|
|
|
// Polyfill IntersectionObserver for components relying on it (e.g., LazyLoad)
|
|
if (!('IntersectionObserver' in globalThis)) {
|
|
// minimal stub sufficient for react-intersection-observer
|
|
class IO {
|
|
constructor(_: any) {}
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
takeRecords() {
|
|
return [];
|
|
}
|
|
}
|
|
// @ts-expect-error test env polyfill
|
|
globalThis.IntersectionObserver = IO;
|
|
}
|
|
|
|
// Polyfill ResizeObserver for components relying on it (e.g., react-resize-detector)
|
|
if (!('ResizeObserver' in globalThis)) {
|
|
class RO {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
}
|
|
globalThis.ResizeObserver = RO as any;
|
|
}
|
|
|
|
// Provide HTMLDocument constructor reference for libs checking it explicitly
|
|
if (!('HTMLDocument' in globalThis)) {
|
|
// @ts-expect-error test env polyfill
|
|
globalThis.HTMLDocument = document?.constructor || (window as any).Document;
|
|
}
|