Skip to content
TypeWire

@tahanabavi/typefetch

documents v1.10.0

The typed HTTP client every other package is built around.

Testing

TypeFetch is designed to be easy to test with mocked fetch.

Example:

ts
global.fetch = vi.fn();

(fetch as any).mockResolvedValueOnce({
ok: true,
json: async () => ({
id: "1",
name: "Taha",
}),
});

const user = await api.user.getUser({
path: {
id: "1",
},
});

expect(user.name).toBe("Taha");

Contract-driven API testing can also be run through the TypeFetch CLI (@tahanabavi/typewire-cli).

bash
npx typewire init
npx typewire test --mode schema
npx typewire test --mode mock
npx typewire test --mode live --base-url http://localhost:3000

Generated reports can be exported as Markdown, HTML, or JSON:

bash
npx typewire test --mode full --format markdown,json,html --output ./typefetch-report/report

Recommended test coverage:

  • Request validation

  • Response validation

  • Path parameter handling

  • Query string generation

  • JSON body serialization

  • Header merging

  • Auth token injection

  • Token provider behavior

  • Middleware execution order

  • Retry behavior

  • Timeout and abort behavior

  • Mock mode

  • Response wrappers

  • Error normalization

  • Encryption middleware

  • Instrumentation events (start / success / error)

  • Runtime overrides (mock / error / latency / schema swap)