Testing
TypeFetch is designed to be easy to test with mocked fetch.
Example:
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).
npx typewire init
npx typewire test --mode schema
npx typewire test --mode mock
npx typewire test --mode live --base-url http://localhost:3000Generated reports can be exported as Markdown, HTML, or JSON:
npx typewire test --mode full --format markdown,json,html --output ./typefetch-report/reportRecommended 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)