Hono Test
Hono API
ts
import type { Hono } from 'hono'
export class HonoHandler {
static apply(app: Hono) {
return app.get('/', async (c) => {
return c.json({ message: 'Hono🔥' })
})
}
}
Test
ts
import { testClient } from 'hono/testing'
import { describe, expect, it } from 'vitest'
import app from '..'
describe('HonoHandler Test', () => {
it('Hono API Test', async () => {
const client = testClient(app)
const res = await client.index.$get()
const input = await res.json()
expect(input).toEqual({ message: 'Hono🔥' })
expect(res.status).toEqual(200)
})
})
Result
sh
<-- GET /
::: GET http://localhost/
--> GET / 200 0ms
✓ src/test/api.test.ts (1)
✓ HonoHandler Test (1)
✓ Hono API Test
Test Files 1 passed (1)
Tests 1 passed (1)