61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import '@testing-library/jest-dom/vitest';
|
|
import { afterAll, afterEach, beforeAll, vi } from 'vitest';
|
|
import { cleanup } from '@testing-library/react';
|
|
import { server } from '@/mocks/server';
|
|
import { api } from '@/lib/api-client';
|
|
import '@/i18n/config';
|
|
|
|
// jsdom is missing a few browser APIs that Radix/sonner touch.
|
|
const globalAny = globalThis as unknown as {
|
|
matchMedia?: unknown;
|
|
ResizeObserver?: unknown;
|
|
};
|
|
|
|
if (typeof globalAny.matchMedia === 'undefined') {
|
|
globalAny.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: vi.fn(),
|
|
removeListener: vi.fn(),
|
|
addEventListener: vi.fn(),
|
|
removeEventListener: vi.fn(),
|
|
dispatchEvent: vi.fn(),
|
|
}));
|
|
}
|
|
|
|
if (typeof globalAny.ResizeObserver === 'undefined') {
|
|
globalAny.ResizeObserver = class {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
};
|
|
}
|
|
|
|
// Radix UI uses pointer capture APIs not present in jsdom.
|
|
if (typeof Element.prototype.hasPointerCapture === 'undefined') {
|
|
Element.prototype.hasPointerCapture = () => false;
|
|
}
|
|
if (typeof Element.prototype.setPointerCapture === 'undefined') {
|
|
Element.prototype.setPointerCapture = () => {};
|
|
}
|
|
if (typeof Element.prototype.releasePointerCapture === 'undefined') {
|
|
Element.prototype.releasePointerCapture = () => {};
|
|
}
|
|
// Radix scroll-into-view
|
|
if (typeof Element.prototype.scrollIntoView === 'undefined') {
|
|
Element.prototype.scrollIntoView = () => {};
|
|
}
|
|
|
|
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
server.resetHandlers();
|
|
// Reset shared client state between tests.
|
|
api.setAccessToken(null);
|
|
localStorage.clear();
|
|
});
|
|
|
|
afterAll(() => server.close());
|