테스트 헬퍼
테스트 헬퍼는 Hono 애플리케이션의 테스트를 더 쉽게 만들어주는 함수를 제공한다.
임포트
ts
import { Hono } from 'hono'
import { testClient } from 'hono/testing'testClient()
testClient()는 첫 번째 인자로 Hono 인스턴스를 받고, Hono Client 객체를 반환한다. 이를 사용하면 편집기의 자동 완성 기능을 활용해 요청을 정의할 수 있다.
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' })
})