-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for inversify/InversifyJS/issues/527
- Loading branch information
1 parent
bd16e7a
commit 585eb3b
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { expect } from "chai"; | ||
import * as express from "express"; | ||
import { Controller, Method, Get, Request, Response, RequestParam } from "../src/decorators"; | ||
import { interfaces } from "../src/interfaces"; | ||
import { METADATA_KEY, PARAMETER_TYPE } from "../src/constants"; | ||
import { InversifyExpressServer } from "../src/server"; | ||
import { Container, injectable } from "inversify"; | ||
import { TYPE } from "../src/constants"; | ||
import * as request from "supertest"; | ||
|
||
describe("Unit Test: Previous bugs", () => { | ||
|
||
it("should support multiple controller methods with param annotations", (done) => { | ||
|
||
let container = new Container(); | ||
|
||
@injectable() | ||
@Controller("/api/test") | ||
class TestController { | ||
@Get("/") | ||
public get( | ||
@Request() req: express.Request, | ||
@Response() res: express.Response | ||
) { | ||
expect(req.url).not.to.eql(undefined); | ||
expect((req as any).setHeader).to.eql(undefined); | ||
expect(res.setHeader).not.to.eql(undefined); | ||
expect((res as any).url).to.eql(undefined); | ||
res.json([{ id: 1 }, { id: 2 }]); | ||
} | ||
@Get("/:id") | ||
public getById( | ||
@RequestParam("id") id: string, | ||
@Request() req: express.Request, | ||
@Response() res: express.Response | ||
) { | ||
expect(id).to.eql("5"); | ||
expect(req.url).not.to.eql(undefined); | ||
expect((req as any).setHeader).to.eql(undefined); | ||
expect(res.setHeader).not.to.eql(undefined); | ||
expect((res as any).url).to.eql(undefined); | ||
res.json({ id: id }); | ||
} | ||
} | ||
|
||
container.bind(TYPE.Controller).to(TestController); | ||
let server = new InversifyExpressServer(container); | ||
let app = server.build(); | ||
|
||
request(app).get("/api/test/") | ||
.expect("Content-Type", /json/) | ||
.expect(200) | ||
.then(response1 => { | ||
expect(Array.isArray(response1.body)).to.eql(true); | ||
expect(response1.body[0].id).to.eql("1"); | ||
expect(response1.body[0].id).to.eql("2"); | ||
}); | ||
|
||
request(app).get("/api/test/5") | ||
.expect("Content-Type", /json/) | ||
.expect(200) | ||
.then(response2 => { | ||
expect(Array.isArray(response2.body)).to.eql(false); | ||
expect(response2.body.id).to.eql("5"); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
585eb3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remojansen This test case is actually failing. I noticed it when i was writing a pull request. My test was producing a similar error but would stop the rest of the tests from executing.
The problem is that you are inputing 1 and 2 on line 29 and expecting "1" and "2" in lines 55 & 56
I have no idea why this isn't causing a test failure.
this message appears
Unit Test: Previous bugs
(node:24900) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected 1 to deeply equal '1'
(node:24900) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js pro