-
-
Notifications
You must be signed in to change notification settings - Fork 377
Closed
Labels
bugSomething isn't workingSomething isn't workingreviewWaiting for issue reporter approvalWaiting for issue reporter approval
Description
What version of Elysia.JS is running?
1.1.3
What platform is your computer?
WSL Ubuntu
What steps can reproduce the bug?
// test.test.ts
import {
t,
Elysia,
ParseError,
NotFoundError,
ValidationError,
InternalServerError,
} from "elysia";
import { describe, it, expect, beforeEach } from "bun:test";
let isOnResponseCalled: boolean;
class CustomError extends Error {}
const app = new Elysia()
.onAfterResponse(() => {
isOnResponseCalled = true;
})
.post("/", () => "yay", {
body: t.Object({
test: t.String(),
}),
})
.get("/customError", () => {
throw new CustomError("whelp");
})
.get("/internalError", () => {
throw new InternalServerError("whelp");
});
beforeEach(() => {
isOnResponseCalled = false;
});
export const newReq = (params?: {
path?: string;
headers?: Record<string, string>;
method?: string;
body?: string;
}) => new Request(`http://localhost${params?.path ?? "/"}`, params);
describe("Error", () => {
it.each([
["NotFoundError", newReq({ path: "/notFound" })],
[
"ParseError",
newReq({
method: "POST",
headers: { "Content-Type": "application/json" },
body: "",
}),
],
[
"ValidationError",
newReq({
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({}),
}),
],
["CustomError", newReq({ path: "/customError" })],
["InternalServerError", newReq({ path: "/internalError" })],
])("%s should call onResponse", async (_name, request) => {
expect(isOnResponseCalled).toBeFalse();
await app.handle(request);
expect(isOnResponseCalled).toBeTrue();
});
});bun testWhat is the expected behavior?
all tests pass:
✓ Error > NotFoundError should call onResponse
✓ Error > ParseError should call onResponse
✓ Error > ValidationError should call onResponse
✓ Error > CustomError should call onResponse
✓ Error > InternalServerError should call onResponseWhat do you see instead?
NotFoundError test fails:
✗ Error > NotFoundError should call onResponse
✓ Error > ParseError should call onResponse
✓ Error > ValidationError should call onResponse
✓ Error > CustomError should call onResponse
✓ Error > InternalServerError should call onResponseAdditional information
works as expected with aot: false
Metadata
Metadata
Labels
bugSomething isn't workingSomething isn't workingreviewWaiting for issue reporter approvalWaiting for issue reporter approval