@modular-react/testing
v1.2.0
Published
Testing utilities for @modular-react modules: mock stores, module resolution, and slot evaluation.
Readme
@modular-react/testing
Router-agnostic testing utilities for modular-react modules. Resolve module contributions (slots, lifecycle) without rendering.
Installation
npm install -D @modular-react/testingWhat's included
resolveModule: resolves module contributions (slots, lifecycle) without renderingcreateMockStore: creates a store pre-populated with test state (uses@modular-react/core's built-in store)- Types:
ResolveModuleOptions,ResolveModuleResult
Usage
import { resolveModule, createMockStore } from "@modular-react/testing";
const { slots, entry, onRegisterCalled } = resolveModule(myModule, {
defaults: { commands: [], badges: [] },
deps: { auth: { user: { isAdmin: true } } },
});
expect(slots.commands).toHaveLength(2);
expect(entry.id).toBe("my-module");For rendering modules with a router, use the router-specific testing packages (@react-router-modules/testing or @tanstack-react-modules/testing).
See the main documentation for the full guide.
