Test utilities from @prepared911/ui/testing for jsdom, fixed time, locales and the design system environment.
@prepared911/ui/testing holds what a consumer's component tests need to render @prepared911/ui the way an app does. It imports no test runner, so it works with Vitest, Jest or any other runner, and it adds no dependency. Nothing in the runtime bundle imports it.
| Export | What it does |
|---|---|
installResizeObserverStub(host?) | Installs a ResizeObserver for jsdom. Observers record what they observe (observe, unobserve, disconnect) and call back only when the test calls resize(element, size). |
installMatchMediaStub(options?, host?) | Installs a matchMedia for jsdom. By default only (min-width: 0px) matches. setMatches(query, matches) changes a result and sends change events (real Event objects with matches and media) to change listeners, onchange and addListener. |
TEST_NOW, testNow() | A fixed instant, Wednesday, January 14, 2026, 15:30 UTC, as a number and as a fresh Date. |
LOCALE_FIXTURES | Locale, time zone and direction sets: default (en-US, UTC), unitedStates, canadianFrench, french, unitedKingdom and hebrew (right to left). Every fixture renders time on a 24-hour clock (15:30 at TEST_NOW in UTC); none shows AM or PM. |
UiTestProviders | Wraps a tree in DesignSystemEnvironment with a fixture's locale, time zone and direction, and an optional link adapter. |
reset(), which forgets observers, lists and overrides between tests, and restore(), which puts back what was installed before. Both take an optional host object, the last argument (installResizeObserverStub(host?), installMatchMediaStub(options?, host?)), so you can install on an iframe's window instead of globalThis.
@prepared911/ui's own Vitest setup installs the same two stubs.
Date (toFake: ["Date"]) unless the test also steps timers forward; faking every timer stops animation frames and timeouts that components wait on.
UiTestProviders does not set dir on the document. A right-to-left test sets document.documentElement.dir = "rtl" itself, as the shell does, and puts it back afterwards.
A component that measures itself through ResizeObserver sees a size only when the test reports one.
resize calls back only the observers that observe that element, with one entry whose contentRect, borderBoxSize and contentBoxSize all report the given size.