Skip to content

Commit

Permalink
Added integration test for non-native promise support
Browse files Browse the repository at this point in the history
  • Loading branch information
RohaanAdvani68 authored and lholznagel committed Aug 28, 2017
1 parent dc5c192 commit 97b2893
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
},
"homepage": "https://github.com/inversify/inversify-express-utils#readme",
"devDependencies": {
"@types/bluebird": "^3.5.8",
"@types/body-parser": "^1.16.3",
"@types/chai": "^4.0.1",
"@types/cookie-parser": "^1.3.30",
"@types/express": "^4.0.34",
"@types/mocha": "^2.2.33",
"@types/sinon": "^2.1.0",
"@types/supertest": "^2.0.0",
"bluebird": "^3.5.0",
"body-parser": "^1.17.1",
"chai": "^4.0.0",
"cookie-parser": "^1.4.3",
Expand Down
36 changes: 36 additions & 0 deletions test/framework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { controller, httpMethod, all, httpGet, httpPost, httpPut, httpPatch,
requestBody, queryParam, requestHeaders, cookies,
next } from "../src/decorators";
import { TYPE, PARAMETER_TYPE } from "../src/constants";
import * as Bluebird from "bluebird";

describe("Integration Tests:", () => {
let server: InversifyExpressServer;
Expand Down Expand Up @@ -63,6 +64,41 @@ describe("Integration Tests:", () => {
.expect(500, done);
});

it("should work for async controller methods using non-native Bluebird promise", (done) => {
@injectable()
@controller("/")
class TestController {
@httpGet("/") public getTest(req: express.Request, res: express.Response) {
return new Bluebird(((resolve) => {
setTimeout(resolve, 100, "GET");
}));
}
}
container.bind<interfaces.Controller>(TYPE.Controller).to(TestController).whenTargetNamed("TestController");

server = new InversifyExpressServer(container);
supertest(server.build())
.get("/")
.expect(200, "GET", done);
});

it("should work for async controller methods, using non-native Bluebird promise, that fails", (done) => {
@injectable()
@controller("/")
class TestController {
@httpGet("/") public getTest(req: express.Request, res: express.Response) {
return new Bluebird(((resolve, reject) => {
setTimeout(reject, 100, "GET");
}));
}
}
container.bind<interfaces.Controller>(TYPE.Controller).to(TestController).whenTargetNamed("TestController");

server = new InversifyExpressServer(container);
supertest(server.build())
.get("/")
.expect(500, done);
});

it ("should work for methods which call nextFunc()", (done) => {
@injectable()
Expand Down

0 comments on commit 97b2893

Please sign in to comment.