From 97b2893b967306bef400f9e0c542648369ea8083 Mon Sep 17 00:00:00 2001 From: rohaanadvani68 Date: Mon, 28 Aug 2017 13:58:03 -0500 Subject: [PATCH] Added integration test for non-native promise support --- package.json | 2 ++ test/framework.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/package.json b/package.json index d0682e35..2fbd9a5f 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "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", @@ -32,6 +33,7 @@ "@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", diff --git a/test/framework.test.ts b/test/framework.test.ts index 420bdcac..bdeb0d56 100644 --- a/test/framework.test.ts +++ b/test/framework.test.ts @@ -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; @@ -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(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(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()