測試輔助工具
測試輔助工具提供函式,讓 Hono 應用程式的測試更容易。
導入
ts
import { Hono } from 'hono'
import { testClient } from 'hono/testing'
testClient()
testClient()
接收 Hono 的實例作為其第一個參數,並返回 Hono 客戶端的物件。透過使用它,您可以使用編輯器完成功能來定義您的請求。
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' })
})