Skip to content

Commit 56233d9

Browse files
committed
Add test of error handling in Koa async middlewares
1 parent e8d6976 commit 56233d9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test/functional/koa-middlewares.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ describe("koa middlewares", () => {
7474

7575
}
7676

77+
class TestCustomAsyncMiddlewareWhichThrows implements KoaMiddlewareInterface {
78+
79+
async use(context: any, next?: Function): Promise<any> {
80+
throw new NotAcceptableError("TestCustomAsyncMiddlewareWhichThrows");
81+
}
82+
83+
}
7784
@Controller()
7885
class KoaMiddlewareController {
7986

@@ -133,6 +140,12 @@ describe("koa middlewares", () => {
133140
return "1234";
134141
}
135142

143+
@Get("/customAsyncMiddlewareWhichThrows")
144+
@UseBefore(TestCustomAsyncMiddlewareWhichThrows)
145+
TestCustomAsyncMiddlewareWhichThrows() {
146+
return "1234";
147+
}
148+
136149
}
137150
});
138151

@@ -199,4 +212,11 @@ describe("koa middlewares", () => {
199212
});
200213
});
201214

202-
});
215+
it("should handle errors in custom async middlewares", () => {
216+
return chakram
217+
.get("http://127.0.0.1:3001/customAsyncMiddlewareWhichThrows")
218+
.then((response: any) => {
219+
expect(response).to.have.status(406);
220+
});
221+
});
222+
});

0 commit comments

Comments
 (0)