Skip to content
Myr

handler.test.ts

This file

Path

adapters/vercel/src/handler.test.ts

38 lines · 1.0 KiB · TypeScript

Last changed by

feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827

History of this file

Take it

feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827

lines 1–38why, one step back
1import { Hono } from 'hono'
2import { handle } from './handler'34describe('Adapter for Next.js', () => {5 it('Should return 200 response', async () => {6 const app = new Hono()7 app.get('/api/author/:name', async (c) => {8 const name = c.req.param('name')9 return c.json({10 path: '/api/author/:name',11 name,12 })13 })14 const handler = handle(app)15 const req = new Request('http://localhost/api/author/hono')16 const res = await handler(req)17 expect(res.status).toBe(200)18 expect(await res.json()).toEqual({19 path: '/api/author/:name',20 name: 'hono',21 })22 })2324 it('Should not use `route()` if path argument is not passed', async () => {25 const app = new Hono().basePath('/api')2627 app.onError((e) => {28 throw e29 })30 app.get('/error', () => {31 throw new Error('Custom Error')32 })3334 const handler = handle(app)35 const req = new Request('http://localhost/api/error')36 expect(() => handler(req)).toThrowError('Custom Error')37 })38})