Orchid ORM Test Factory is a companion library for Orchid ORM that simplifies creating mock data for tests. Version 1.0.130 is the current stable release, updated regularly alongside Orchid ORM. It uses @faker-js/faker for generating realistic fake data and provides a declarative API to define factories for database models. Unlike generic factories, it integrates directly with Orchid ORM's model layers, supporting associations, custom column types, and lifecycle hooks. The factory is type-safe, fully typed with TypeScript, and designed for seamless use in integration or unit tests.
npm install orchid-orm-test-factoryNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to define a factory for a User model, build an object without persisting, create a single record, create multiple records, and override attributes.
Ensure the factory callback returns a synchronous object. If async data is needed, precompute it outside the factory.
Use 'db.user' (where 'db' is your Orchid ORM instance) instead of a plain 'user' object.
Prefer using the 'f' parameter passed to the callback (currently undocumented).
Change 'import orchidFactory from 'orchid-orm-test-factory'' to 'import { factory } from 'orchid-orm-test-factory''.Run 'npm install orchid-orm-test-factory @faker-js/faker'.
Ensure 'db' is your Orchid ORM database instance and 'user' is a defined model.