Skip to content

Commit 8791818

Browse files
committed
test: add case for middleware with 404 Response support
1 parent a05c860 commit 8791818

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/middleware.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { beforeEach } from "vitest";
22
import { describeMatrix } from "./_setup.ts";
33
import { H3 } from "../src/h3.ts";
44
import { defineHandler } from "../src/handler.ts";
5+
import { Hono } from "hono";
56

67
describeMatrix("middleware", (t, { it, expect }) => {
78
beforeEach(() => {
@@ -128,4 +129,21 @@ describeMatrix("middleware", (t, { it, expect }) => {
128129
expect(response.status).toBe(200);
129130
expect(await response.json()).toMatchObject({ log: expect.any(String) });
130131
});
132+
133+
it("can mount sub-router as middleware", async () => {
134+
t.app.get("/", () => "hi!");
135+
136+
const honoApp = new Hono().get("/hello", (c) => {
137+
return c.text("world");
138+
});
139+
t.app.use((event) => honoApp.fetch(event.req));
140+
141+
const res = await t.fetch("/hello");
142+
expect(res.status).toBe(200);
143+
expect(await res.text()).toBe("world");
144+
145+
const res2 = await t.fetch("/");
146+
expect(res2.status).toBe(200);
147+
expect(await res2.text()).toBe("hi!");
148+
});
131149
});

0 commit comments

Comments
 (0)