Skip to content

Commit

Permalink
add error test
Browse files Browse the repository at this point in the history
  • Loading branch information
cjquines committed Dec 11, 2024
1 parent 104476b commit eaa9575
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/hono/src/honoPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,19 @@ describe("basic routing", () => {
describe("hono passthrough", () => {
const baseApi = stl.api({
basePath: "/api",
resources: {},
resources: {
posts: stl.resource({
summary: "posts",
actions: {
retrieve: stl.endpoint({
endpoint: "GET /api/posts",
handler: () => {
throw new Error("arbitrary error");
},
}),
},
}),
},
});

const app = new Hono();
Expand All @@ -181,6 +193,9 @@ describe("hono passthrough", () => {
app.notFound((c) => {
return c.text("custom not found", 404);
});
app.onError((err, c) => {
return c.text(`custom error: ${err.message}`, 500);
});

test("public passthrough", async () => {
const response = await app.request("/public/foo/bar");
Expand All @@ -193,4 +208,12 @@ describe("hono passthrough", () => {
expect(response).toHaveProperty("status", 404);
expect(await response.text()).toMatchInlineSnapshot(`"custom not found"`);
});

test("error passthrough", async () => {
const response = await app.request("/api/posts");
expect(response).toHaveProperty("status", 500);
expect(await response.text()).toMatchInlineSnapshot(
`"custom error: arbitrary error"`
);
});
});

0 comments on commit eaa9575

Please sign in to comment.