Introduction
Test fixtures and offline mock data drift from the real shape over time. A field is renamed in the schema, the fixture is not, and nothing fails until a real request breaks.
shamock closes that gap with two tools:
- Validation. Check any mock value against the same Standard Schema validator (Zod, Valibot, ArkType…) your app uses. A stale fixture fails loudly.
- Mock API. Serve seed data from an in-process REST API that answers
fetchcalls. No server needed.
shamock needs only a { schema } object, not an SDK resource type. It has zero dependencies and requires Node.js 22 or later.
Install
Section titled “Install”pnpm add shamockA minimal example
Section titled “A minimal example”import { parseMock } from 'shamock'import { z } from 'zod'
const user = { schema: z.object({ id: z.number(), name: z.string() }) }
await parseMock(user, { id: 1, name: 'Alice' })It throws MockValidationError when the value does not match the schema.
From here:
- Mock API: serve seed data over
fetch. - Pairing with nexdk: use shamock next to a nexdk SDK.
- shamock API: every runtime export.