Skip to content

Commit 17a53c6

Browse files
committed
Add test case for returning error in json controller
1 parent b6ff09d commit 17a53c6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

test/functional/controller-methods.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ describe("controller methods", () => {
130130

131131
@Get("/text-plain-error")
132132
@ContentType("text/plain")
133-
error(): never {
133+
textError(): never {
134+
throw new UnauthorizedError();
135+
}
136+
137+
@Get("/json-error")
138+
jsonError(): never {
134139
throw new UnauthorizedError();
135140
}
136141
}
@@ -316,9 +321,20 @@ describe("controller methods", () => {
316321
expect(response).to.have.header("content-type", (contentType: string) => {
317322
expect(contentType).to.match(/text\/plain/);
318323
});
324+
expect(typeof response.body).to.equals("string");
319325
expect(response.body).to.match(/UnauthorizedError.HttpError/);
320326
});
321327
});
322328

329+
describe("should respond with 401 and aplication/json when UnauthorizedError throwed in standard json controller's method", () => {
330+
assertRequest([3001, 3002], "get", "json-controller/json-error", response => {
331+
expect(response).to.have.status(401);
332+
expect(response).to.have.header("content-type", (contentType: string) => {
333+
expect(contentType).to.match(/application\/json/);
334+
});
335+
expect(typeof response.body).to.equals("object");
336+
expect(response.body.name).to.equals("UnauthorizedError");
337+
});
338+
});
323339

324340
});

0 commit comments

Comments
 (0)