Registry / testing / zocker

zocker

JSON →
library3.0.0jsnpmunverified

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 zocker
INSTALL
IMPORT
SIG · ZOCKER
Z
zocker
testingjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

z
import { z } from 'zod';
While a peer dependency, Zod's `z` object is fundamental for defining schemas that Zocker consumes.
zocker
import { zocker } from 'zocker';
import zocker from 'zocker'; const zocker = require('zocker');
The primary `zocker` function is a named export. ESM-only usage is assumed for v3.0.0 and above. CommonJS `require` is not supported in modern versions.
ZockerOptions
import type { ZockerOptions } from 'zocker';
import { ZockerOptions } from 'zocker';
Type imports for configuration options are common for type-aware tooling.

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.

import { z } from 'zod'; import { zocker } from 'zocker'; // Define a Zod schema for a User const UserSchema = z.object({ id: z.string().uuid(), name: z.string().min(3).max(50), email: z.string().email(), age: z.number().int().min(18).max(99), isActive: z.boolean(), roles: z.array(z.enum(['admin', 'editor', 'viewer'])).min(1), createdAt: z.date().default(() => new Date()), }); // Create a zocker instance for the User schema const generateUser = zocker(UserSchema); // Generate a single user object const user = generateUser(); console.log('Generated User:', user); // Generate multiple user objects (e.g., 5 users) const users = zocker(UserSchema, { seed: 123 }).generateMany(5); console.log('Generated Users (many):', users);
Debug
Known issues
breakingVersion 1.0.0 introduced a complete overhaul of the configuration API, replacing the old Generator-based system with a new fluent API. This change breaks all existing setups, including those without custom generators.
fix
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.
affects: >=1.0.0
gotchaWhen using `supply` or `override` methods, incorrect type definitions were present in versions prior to 1.2.1, leading to potential TypeScript errors or unexpected behavior when providing custom generation logic.
fix
Upgrade to zocker version 1.2.1 or newer to resolve type definition issues with `supply` and `override`.
affects: <1.2.1
gotchaSupport for Zod's `readonly` schemas was introduced in v1.4.0. Using `zocker` with `readonly` schemas in earlier versions might lead to unexpected behavior or incomplete data generation.
fix
Ensure you are on zocker version 1.4.0 or higher if your Zod schemas utilize `readonly` modifiers.
affects: <1.4.0
Errors
Common errors & fixes
TypeError: (0 , zocker__WEBPACK_IMPORTED_MODULE_1__.zocker) is not a function
Attempting to use `zocker` via CommonJS `require()` or as a default import in an ESM context.
fix
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.
TS2307: Cannot find module 'zocker' or its corresponding type declarations.
The 'zocker' package is not installed, or TypeScript cannot locate its type definitions. This can happen with incorrect import paths or mismatched TypeScript configurations.
fix
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'`.
Error: Zod schema not found (zocker requires a Zod schema to generate data)
This error likely indicates that the `zod` peer dependency is missing or its version is incompatible with `zocker`.
fix
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`).
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
zodrequiredRequired for defining the schemas that zocker generates data from. Zocker relies on Zod's schema definitions for its core functionality.
Agent activity
53 hits · last 30 days
node
44
OpenAI (training)
1
Resources
zocker — npm install zocker · libregistry