Use Case
Using MockHero with Jest for Deterministic Test Fixtures
The Pattern
Generate test data once with a deterministic seed, save to __fixtures__/, and import from your Jest tests. No network calls on each run, but still realistic data.
// scripts/gen-fixtures.ts
import fs from "node:fs";
const data = await fetch("https://api.mockhero.dev/api/v1/generate", {
method: "POST",
headers: { "x-api-key": process.env.MOCKHERO_API_KEY!, "Content-Type": "application/json" },
body: JSON.stringify({
seed: 1,
tables: [{
name: "users", count: 20, fields: [
{ name: "id", type: "uuid" },
{ name: "email", type: "email" }
]
}]
})
}).then(r => r.json());
fs.writeFileSync("__fixtures__/users.json", JSON.stringify(data.users, null, 2));
// users.test.ts
import users from "../__fixtures__/users.json";
test("handles 20 users", () => {
expect(users).toHaveLength(20);
});
Get Started
M
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key