Test utilities
@usemotif/test-utils ships the renderer-agnostic conformance suite the web and native
bindings test themselves against, plus a small set of Vitest matchers application tests can
consume. Useful when you are wrapping motif primitives in your own components and want to
exercise the cross-renderer invariants directly.
assertConformance
assertConformance
stablefunction assertConformance(adapter: RendererAdapter, c: ConformanceCase): void
The renderer-specific adapter that implements the resolved-style contract. The internal renderers (@usemotif/react, @usemotif/react-native) supply these; application code rarely does.
The single case to render and assert. Loop `standardCases` to run the full suite.
Renders one case through the adapter and throws an Error describing any mismatch between the
adapter's output and the case's expect* fields. It asserts a single case — the caller loops
standardCases and wraps each in its own it(...) block.
The suite is renderer-agnostic. It exercises tokens, themes, variants, responsive resolution,
pseudo-states, and motion props through the adapter's render function and checks the
output against fixed expectations.
standardCases
standardCases
stableconst standardCases: readonly ConformanceCase[]
The case list assertConformance is run against. Exposed so applications can run a subset, run
additional adapters against just the cases they care about, or extend the suite with custom
cases of the same shape.
defaultTestTheme
defaultTestTheme
stableconst defaultTestTheme: Theme
A small fixed theme the conformance suite uses. Includes enough primitive and semantic tokens
to exercise references, fallbacks, and responsive resolution without dragging in the full
@usemotif/tokens defaults. Reach for it when you need a stable theme value in a unit test.
motifMatchers
motifMatchers
stableconst motifMatchers: VitestMatchers
A Vitest matcher pack covering motif-shaped assertions. Register once in your test setup file
and the matchers become available on every expect.
Both matchers operate on a RendererOutput, so the same assertion reads identically against any
renderer. Available matchers:
| Matcher | Asserts |
|---|---|
toHaveStyle(bag) | The inline (unconditional) style on the rendered root contains every entry of bag. Subset match — extra keys are tolerated. |
toHaveStyleAt(scope, bag) | The output applies bag under scope — an @media …, @container …, or :pseudo selector. Subset match within the scoped rule. |
Types
Related
- Testing guide — full setup including
@testing-library/reactand themotifMatcherswire-up. - Cross-platform — why a renderer-agnostic contract exists.