import "@testing-library/jest-dom/vitest"; /** * Sets up React Testing Library and Okta authentication mocks for testing. * * Behaviour: * - The top-level `afterEach` further up this file (which clears mocks * and runs RTL `cleanup()`) is registered as a side effect of importing * this module - that's intentional and existed before this refactor. * - Calling `setupReactTestingLibrary()` additionally: * 1. Registers the `@okta/okta-react` mock via `vi.doMock` so * `useOktaAuth()` returns a fixed authenticated session. Opt-in: * the mock is NOT hoisted, so tests that need the real okta * hook (or their own mock) are unaffected unless they explicitly * call this. * 2. Installs the tanstack-router Response polyfill (keeps it * opt-in because it mutates `globalThis.Response`); * 3. Calls `setupTranslations()` so the * `useTranslation`/`useNamespaceTranslation` hooks always * return a mocked i18next instance. Under Vitest, the * shared jest-preset's `setupFilesAfterEnv` is no longer * loaded, so projects that previously got translation * setup "for free" otherwise blow up at the first * `i18NextInstance.exists is not a function` call. Baking * it in here means projects can't forget it - the cost is * mocking i18n in tests that don't use it (harmless: the * mock only kicks in if the spec imports react-i18next). * 4. Installs `setupMatchMediaMock()`, `setupResizeObserver()` * and `setupIntersectionObserver()`. Every component test * needs these three under jsdom, and missing any of them * causes React's render to throw, which `vitest-fail-on-console` * then re-raises as "Expected test not to call console.error()". * Under jest the workspace preset installed them via * `setupFilesAfterEnv`; under vitest only what each project's * setup file explicitly imports runs, so most setup files * called `setupReactTestingLibrary()` plus `setupFailOnConsole()` * but forgot the basic-DOM triplet. Folding the triplet in * here means "set up RTL" reads naturally as "set up * everything you need to render a component". * * @example * import { setupReactTestingLibrary } from '@trackunit/react-vite-test-setup'; * setupReactTestingLibrary(); */ export declare const setupReactTestingLibrary: () => void;