Use Case
Mocha + Chai Fixtures with MockHero
Fixture Loader
// test/fixtures.mjs
export async function loadFixtures() {
return 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: 3,
tables: [{
name: "books", count: 30, fields: [
{ name: "id", type: "uuid" },
{ name: "title", type: "book_title" },
{ name: "author", type: "full_name" }
]
}]
})
}).then(r => r.json());
}
// test/books.test.mjs
import { expect } from "chai";
import { loadFixtures } from "./fixtures.mjs";
let data;
before(async () => { data = await loadFixtures(); });
it("returns 30 books", () => {
expect(data.books).to.have.length(30);
});
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