Use Case
Vitest Fixtures with MockHero: Fast, Realistic, Deterministic
Generate Once, Import Everywhere
// scripts/fixtures.ts
import fs from "node:fs/promises";
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: 7,
tables: [
{ name: "products", count: 50, fields: [
{ name: "id", type: "uuid" },
{ name: "name", type: "product_name" },
{ name: "price", type: "price" }
]}
]
})
}).then(r => r.json());
await fs.writeFile("src/__fixtures__/products.json", JSON.stringify(data.products));
// src/products.test.ts
import { test, expect } from "vitest";
import products from "./__fixtures__/products.json";
test("catalog has 50 products", () => {
expect(products).toHaveLength(50);
});
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