{"id":15070,"library":"zocker","title":"Zocker: Zod Schema Test Data Generator","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/LorisSigrist/zocker","tags":["javascript","mock-data","zod","typescript"],"install":[{"cmd":"npm install zocker","lang":"bash","label":"npm"},{"cmd":"yarn add zocker","lang":"bash","label":"yarn"},{"cmd":"pnpm add zocker","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for defining the schemas that zocker generates data from. Zocker relies on Zod's schema definitions for its core functionality.","package":"zod","optional":false}],"imports":[{"note":"While a peer dependency, Zod's `z` object is fundamental for defining schemas that Zocker consumes.","symbol":"z","correct":"import { z } from 'zod';"},{"note":"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.","wrong":"import zocker from 'zocker';\nconst zocker = require('zocker');","symbol":"zocker","correct":"import { zocker } from 'zocker';"},{"note":"Type imports for configuration options are common for type-aware tooling.","wrong":"import { ZockerOptions } from 'zocker';","symbol":"ZockerOptions","correct":"import type { ZockerOptions } from 'zocker';"}],"quickstart":{"code":"import { z } from 'zod';\nimport { zocker } from 'zocker';\n\n// Define a Zod schema for a User\nconst UserSchema = z.object({\n  id: z.string().uuid(),\n  name: z.string().min(3).max(50),\n  email: z.string().email(),\n  age: z.number().int().min(18).max(99),\n  isActive: z.boolean(),\n  roles: z.array(z.enum(['admin', 'editor', 'viewer'])).min(1),\n  createdAt: z.date().default(() => new Date()),\n});\n\n// Create a zocker instance for the User schema\nconst generateUser = zocker(UserSchema);\n\n// Generate a single user object\nconst user = generateUser();\nconsole.log('Generated User:', user);\n\n// Generate multiple user objects (e.g., 5 users)\nconst users = zocker(UserSchema, { seed: 123 }).generateMany(5);\nconsole.log('Generated Users (many):', users);","lang":"typescript","description":"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."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade to zocker version 1.2.1 or newer to resolve type definition issues with `supply` and `override`.","message":"When 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.","severity":"gotcha","affected_versions":"<1.2.1"},{"fix":"Ensure you are on zocker version 1.4.0 or higher if your Zod schemas utilize `readonly` modifiers.","message":"Support 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.","severity":"gotcha","affected_versions":"<1.4.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `zocker` via CommonJS `require()` or as a default import in an ESM context.","error":"TypeError: (0 , zocker__WEBPACK_IMPORTED_MODULE_1__.zocker) is not a function"},{"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'`.","cause":"The 'zocker' package is not installed, or TypeScript cannot locate its type definitions. This can happen with incorrect import paths or mismatched TypeScript configurations.","error":"TS2307: Cannot find module 'zocker' or its corresponding type declarations."},{"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`).","cause":"This error likely indicates that the `zod` peer dependency is missing or its version is incompatible with `zocker`.","error":"Error: Zod schema not found (zocker requires a Zod schema to generate data)"}],"ecosystem":"npm"}