Appearance
测试助手
¥Testing Helper
Testing Helper 提供使 Hono 应用测试更容易的功能。
¥The Testing Helper provides functions to make testing of Hono applications easier.
导入
¥Import
ts
import { Hono } from 'hono'
import { testClient } from 'hono/testing'
testClient()
testClient()
将 Hono 的实例作为其第一个参数并返回 Hono 客户端 的对象。通过使用它,你可以使用编辑器完成定义你的请求。
¥The testClient()
takes an instance of Hono as its first argument and returns an object of the Hono Client. By using this, you can define your request with the editor completion.
ts
import { testClient } from 'hono/testing'
it('test', async () => {
const app = new Hono().get('/search', (c) =>
c.json({ hello: 'world' })
)
const res = await testClient(app).search.$get()
expect(await res.json()).toEqual({ hello: 'world' })
})