Mock Hono route handlers with Zod schema-valid responses for testing (no HTTP roundtrip needed) #5000
gonll
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone! I wanted to share a small testing utility I built for Hono projects
that use Zod for request/response validation.
The problem
Testing Hono routes usually means spinning up a real server or hand-writing
response fixtures that silently drift from your actual schemas over time.
If you're already using Zod to describe your response shapes, your schemas are
the source of truth, so why not generate test responses directly from them?
What I built
zodmint/honogives you two utilities:mockHonoHandlerdrops a schema-valid mock handler into any route:mockHonoAppbuilds a complete stub API in one call:Every generated value is guaranteed to pass
schema.safeParse(v).success === true.Uses
app.request()directly so no HTTP roundtrip and no server needed.Install
Full docs: github.com/gonll/zodmint
Would love feedback, especially if you have patterns around
@hono/zod-validatorthat this could integrate with better.
Beta Was this translation helpful? Give feedback.
All reactions