テストヘルパー
テストヘルパーは、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' })
})