Zocker is a library designed to generate realistic, type-safe test data directly from your Zod schemas. It provides a fluent API for defining how mock data should be created, allowing for customization of various Zod types and the ability to override generation rules globally or for specific schema paths. The current stable version is 3.0.0, which solidified its intuitive fluent API after a significant breaking change in v1.0.0. While there isn't a strict release cadence, minor and patch versions are released as new Zod features are supported or bug fixes are implemented. Zocker differentiates itself by deeply integrating with Zod, leveraging the schema definition itself to ensure generated data adheres to the schema's constraints and types, making it ideal for robust testing and prototyping.
npm install zockerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Zod schema and then use `zocker` to generate both single and multiple mock data objects that conform to that schema.
Migrate your zocker configuration and data generation calls to the new fluent API as described in the README. The old `configure` and generator functions are no longer available.
Upgrade to zocker version 1.2.1 or newer to resolve type definition issues with `supply` and `override`.
Ensure you are on zocker version 1.4.0 or higher if your Zod schemas utilize `readonly` modifiers.
Ensure you are using named imports for `zocker`: `import { zocker } from 'zocker';`. If in a CommonJS environment, consider configuring your project for ESM or use a transpiler.Verify that `zocker` is installed (`npm install zocker` or `yarn add zocker`). Check your `tsconfig.json` for correct `moduleResolution` (e.g., `bundler` or `node16`) and `module` settings (e.g., `esnext`). Ensure correct import path `from 'zocker'`.
Install `zod` as a dependency: `npm install zod` or `yarn add zod`. Ensure the installed `zod` version matches `zocker`'s peer dependency requirement (e.g., `^3.25.0 || ^4.0.0`).