@tanstack-react-modules/testing
v2.4.0
Published
Testing utilities for TanStack Router modules. Render modules in isolation with mocked dependencies.
Readme
@tanstack-react-modules/testing
Testing utilities for TanStack Router modules. Render modules in isolation with mocked dependencies.
Installation
npm install -D @tanstack-react-modules/testingWhat's included
renderModule: renders a module with TanStack Router in a test environmentresolveModule: resolves module contributions (slots, lifecycle) without renderingcreateMockStore: creates a zustand store pre-populated with test state- Types:
RenderModuleOptions,ResolveModuleOptions,ResolveModuleResult
Usage
import { renderModule, createMockStore } from "@tanstack-react-modules/testing";
const result = await renderModule(billingModule, {
route: "/billing",
deps: {
auth: createMockStore<AuthStore>({ isAuthenticated: true }),
httpClient: { get: vi.fn() },
},
});
expect(result.getByText("Billing Dashboard")).toBeTruthy();Both renderModule and resolveModule automatically evaluate dynamicSlots when present on a module, using the provided deps to build the dependencies snapshot.
See the main documentation for the full guide.
