Skip to content

Commit b48588f

Browse files
committed
test: fix definer tests
1 parent 0b9413d commit b48588f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/core/definer.test.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ describe("defineRoute", () => {
3131
mockAction.mockResolvedValue(new Response("Success"));
3232

3333
const nextJsRouteHandler = route.GET;
34-
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
34+
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
3535

3636
expect(mockAction).toHaveBeenCalledWith({
3737
pathParams: null,
3838
queryParams: null,
3939
body: null,
40-
});
40+
}, mockRequest);
4141

4242
expect(response).toBeInstanceOf(Response);
4343
expect(response.status).toBe(200);
@@ -72,7 +72,7 @@ describe("defineRoute", () => {
7272
pathParams: { id: "123" },
7373
queryParams: null,
7474
body: { name: "Test" },
75-
});
75+
}, mockRequest);
7676

7777
expect(response).toBeInstanceOf(Response);
7878
expect(response.status).toBe(201);
@@ -100,7 +100,7 @@ describe("defineRoute", () => {
100100
});
101101

102102
const nextJsRouteHandler = route.POST;
103-
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
103+
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
104104

105105
expect(response).toBeInstanceOf(Response);
106106
expect(response.status).toBe(400);
@@ -133,7 +133,7 @@ describe("defineRoute", () => {
133133
});
134134

135135
const nextJsRouteHandler = route.PUT;
136-
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
136+
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
137137

138138
expect(response).toBeInstanceOf(Response);
139139
expect(response.status).toBe(400);
@@ -149,15 +149,19 @@ describe("defineRoute", () => {
149149
description: "Fetches example data",
150150
tags: ["example"],
151151
action: () => {
152-
throw new Error("Internal Error");
152+
// eslint-disable-next-line no-constant-condition
153+
if (1 + 1 === 2) {
154+
throw new Error("Internal Error");
155+
}
156+
return Response.json({ message: "Internal Error" }, { status: 500 });
153157
},
154158
responses: {
155159
200: { description: "OK" },
156160
},
157161
});
158162

159163
const nextJsRouteHandler = route.GET;
160-
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
164+
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
161165

162166
expect(response).toBeInstanceOf(Response);
163167
expect(response.status).toBe(500);
@@ -238,7 +242,7 @@ describe("defineRoute", () => {
238242

239243
const nextJsRouteHandler = route.GET;
240244

241-
await nextJsRouteHandler(mockRequest as unknown as Request, {});
245+
await nextJsRouteHandler(mockRequest as unknown as Request);
242246

243247
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("You tried to add pathParams to a route"));
244248

@@ -267,7 +271,7 @@ describe("defineRoute", () => {
267271

268272
const nextJsRouteHandler = route.POST;
269273

270-
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
274+
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
271275
const bodyText = await response.text();
272276

273277
expect(response).toBeInstanceOf(Response);
@@ -300,7 +304,7 @@ describe("defineRoute", () => {
300304

301305
const nextJsRouteHandler = route.GET;
302306

303-
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
307+
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
304308
const bodyText = await response.text();
305309

306310
expect(response).toBeInstanceOf(Response);

0 commit comments

Comments
 (0)