31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
// Optional: configure or set up a testing framework before each test.
|
|
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.*`
|
|
|
|
// Used for __tests__/testing-library.js
|
|
// Learn more: https://github.com/testing-library/jest-dom
|
|
import '@testing-library/jest-dom';
|
|
|
|
// next/jest loads .env / .env.test but not .env.development, so NEXT_PUBLIC_API_URL (required by
|
|
// `@/config`) is absent in tests. Any test that renders a component using a `services/{domain}` hook pulls
|
|
// the real `clientApi` → `@/config` at import time, which throws without this. Provide a harmless default.
|
|
process.env.NEXT_PUBLIC_API_URL = process.env.NEXT_PUBLIC_API_URL || 'https://localhost:5002';
|
|
|
|
// To get 'next/router' working with tests
|
|
jest.mock('next/router', () => require('next-router-mock'));
|
|
|
|
// jsdom does not implement window.matchMedia, which MUI's CSS-variable theme
|
|
// (CssVarsProvider) relies on to track the system color-scheme preference.
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: (query: string) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(), // Deprecated, but still called by MUI for old browsers
|
|
removeListener: jest.fn(), // Deprecated
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
}),
|
|
});
|