zod-testing
Testing patterns for Zod schemas using Jest and Vitest. Covers schema correctness testing, mock data generation, error assertion patterns, integration testing with API handlers and forms, snapshot testing with z.toJSONSchema(), and property-based testing. Baseline: zod ^4.0.0. Triggers on: test files for Zod schemas, zod-schema-faker imports, mentions of "test schema", "schema test", "zod mock", "zod test", or schema testing patterns.
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/anivar/zod-testingWhat This Skill Does
The zod-testing skill provides a comprehensive suite of utilities and patterns for validating Zod schemas in TypeScript environments. It streamlines the testing process by enforcing reliable patterns for Zod v4, covering essential aspects such as schema correctness, error message assertions, and integration testing. By providing standardized methods to verify schema boundaries and structure, it ensures that your application's data validation layer remains robust against regressions.
Installation
You can install this skill into your environment using the following OpenClaw command:
clawhub install openclaw/skills/skills/anivar/zod-testing
Use Cases
- Schema Correctness: Easily assert that schemas successfully parse valid data and correctly reject invalid inputs using the recommended
safeParse()methodology. - Error Handling Validation: Use
z.flattenError()patterns to ensure specific error messages are surfaced, critical for API responses and form validation feedback. - Snapshot Testing: Utilize
z.toJSONSchema()to generate snapshots that detect unintended schema structure changes during CI/CD pipelines. - Property-based Testing: Facilitate fuzz testing to ensure your schemas handle edge cases and unexpected inputs gracefully.
- Integration Testing: Validate that schemas correctly interface with form libraries, database layers, and API request/response handlers.
Example Prompts
- "Generate a Vitest suite for my
UserSchemathat tests both valid payloads and negative age edge cases." - "How can I use
z.toJSONSchema()with Jest snapshots to track changes in my API validation schema?" - "Refactor my schema tests to use
safeParse()instead ofparse()to avoid unexpected test crashes."
Tips & Limitations
- Version Sensitivity: Always keep in mind that Zod v4 includes breaking changes compared to previous versions, such as the removal of
z.nativeEnum(). This skill is optimized for v4+. Always verify your local package version. - Safe Practices: Always prioritize
safeParse()overparse()in tests. Usingparse()can lead to unhandled exceptions that crash the test runner, whereassafeParse()returns a result object that allows for descriptive assertions. - Data Integrity: While mock data generation is supported, ensure that your generated fixtures realistically represent the full range of possible inputs allowed by your schema to prevent 'false green' test results.
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-anivar-zod-testing": {
"enabled": true,
"auto_update": true
}
}
}Tags(AI)
Related Skills
jest
Jest best practices, patterns, and API guidance for JavaScript/TypeScript testing. Covers mock design, async testing, matchers, timer mocks, snapshots, module mocking, configuration, and CI optimization. Baseline: jest ^29.0.0 / ^30.0.0. Triggers on: jest imports, describe, it, test, expect, jest.fn, jest.mock, jest.spyOn, mentions of "jest", "unit test", "test suite", or "mock".
redux-saga-testing
Write tests for Redux Sagas using redux-saga-test-plan, runSaga, and manual generator testing. Covers expectSaga (integration), testSaga (unit), providers, partial matchers, reducer integration, error simulation, and cancellation testing. Works with Jest and Vitest. Triggers on: test files for sagas, redux-saga-test-plan imports, mentions of "test saga", "saga test", "expectSaga", "testSaga", or "redux-saga-test-plan".
zod
Zod v4 best practices, patterns, and API guidance for schema validation, parsing, error handling, and type inference in TypeScript applications. Covers safeParse, object composition, refinements, transforms, codecs, branded types, and v3→v4 migration. Baseline: zod ^4.0.0. Triggers on: zod imports, z.object, z.string, z.infer, safeParse, mentions of "zod", "schema validation", "zod v4", or "z.enum".
redux-saga
Redux-Saga best practices, patterns, and API guidance for building, testing, and debugging generator-based side-effect middleware in Redux applications. Covers effect creators, fork model, channels, testing with redux-saga-test-plan, concurrency, cancellation, and modern Redux Toolkit integration. Baseline: redux-saga 1.4.2. Triggers on: saga files, redux-saga imports, generator-based middleware, mentions of "saga", "takeEvery", "takeLatest", "fork model", or "channels".
msw
MSW (Mock Service Worker) v2 best practices, patterns, and API guidance for API mocking in JavaScript/TypeScript tests and development. Covers handler design, server setup, response construction, testing patterns, GraphQL, and v1-to-v2 migration. Baseline: msw ^2.0.0. Triggers on: msw imports, http.get, http.post, HttpResponse, setupServer, setupWorker, graphql.query, mentions of "msw", "mock service worker", "api mocking", or "msw v2".