Skip to main content
The Testing helper provides utilities for testing your Hono applications with type-safe request methods.

Import

Basic Usage

Create a type-safe client for testing your app:

Features

Type-Safe Requests

The test client provides full TypeScript support:

Query Parameters

Test routes with query parameters:

Request Headers

Include custom headers in requests:

JSON Request Body

Send JSON data in requests:

Form Data

Test file uploads and form submissions:

Environment Variables

Test with environment bindings:

Execution Context

Provide execution context for testing:

Client Options

Customize the test client:

Testing Patterns

Unit Tests

Test individual routes:

Integration Tests

Test complete workflows:

Testing Middleware

Test middleware behavior:

Testing Error Cases

Test error handling:

Testing with Different Test Frameworks

Vitest

Jest

Node Test Runner

URL Generation

Generate URLs for routes:

Mock Responses

Mock external dependencies:

Best Practices

Type Safety

Leverage TypeScript for compile-time type checking of requests

Isolate Tests

Create a new test client for each test to avoid side effects

Test Real Paths

Test actual user paths through your application

Mock External APIs

Mock external dependencies for faster, reliable tests
The test client uses the same Hono client (hc) used in production, ensuring your tests reflect real usage.
Test clients run against your Hono app directly without HTTP overhead, making tests fast and reliable.