honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
389 stars 138 forks source link

@hono/zod-openapi: Error 404 when calling API route from unit test #568

Closed mann1996 closed 1 month ago

mann1996 commented 2 months ago

Summary

I am writing Unit tests for my API and I am getting error 404 for the routes that are defined using @hono/zod-openapi createRoute method. Routes that are defined using app.get or app.post are working fine. This issue is only in Tests and not when using browser or postman.

Screenshot

image

Environment

OS: MacOS 14.5 (Apple Silicon) Testing Library: Vitest Runtime: Cloudflare Workers

Reproduction Code: https://github.com/jaspreet-singh-96/worker-test

yusukebe commented 2 months ago

Hi @mann1996

Try to use showRoutes for debugging:

showRoutes(app)

According to this, the endpoint path is not correct.

GET  /api/docs
GET  /api/doc.json
GET  /api/direct
GET  /api/api/openapi
mann1996 commented 2 months ago

I will try it

For now I have removed base path from app.basePath