Unit tests with seeded data
Use the seed parameter so assertions stay stable across CI runs.
// Vitest / Jest style helper
export async function fetchMockUsers(seed = "tests") {
const res = await fetch("https://free-api-backend.vercel.app/users?count=5&seed=" + seed);
const json = await res.json();
return json.data;
}
test("loads users from mock API", async () => {
const users = await fetchMockUsers();
expect(users).toHaveLength(5);
expect(users[0]).toHaveProperty("email");
});E2E with Playwright
Fulfill routes with ApiGenerator JSON or call the mock API directly from the browser.
// Playwright example
await page.route("**/users*", async (route) => {
const res = await fetch("https://free-api-backend.vercel.app/users?count=3&seed=e2e");
const body = await res.text();
await route.fulfill({ status: 200, contentType: "application/json", body });
});Frequently asked questions
Why use a live mock API in tests?
It exercises real HTTP parsing and loading states without maintaining large fixture files. Seed keeps payloads stable between runs.
Should E2E tests call the public API directly?
You can, or proxy through page.route / MSW. Either way, ApiGenerator provides consistent fake JSON shapes for UI assertions.
Is mock data safe for CI?
Yes for prototyping tests. Do not send secrets or PII to the mock API, and prefer seeded built-in endpoints for speed.