Guides

Testing

Swap the network for a stub in unit tests.

Stub fetch

Pass your own fetch to the client. No global mocks, so tests can run in parallel.

ts
import { expect, test } from "bun:test";import { createClient } from "tempo-http";test("reads a user", async () => {  const api = createClient({    baseUrl: "https://api.test",    fetch: async () => Response.json({ id: 42, name: "Ada" }),  });  expect(await api.get("/users/42")).toEqual({ id: 42, name: "Ada" });});

Retries in tests

Set retry: { delay: 0 } so a test of the failure path doesn't wait for backoff.

Was this page helpful?

Updated