njsetn:testing_http_endpoints_with_supertest
Tester les applications http comme les apps express.
→ npmjs.com/package/supertest
npm install supertest –save-dev
// app-spec.js
var request = require("supertest");
(...)
it("Loads the home page", function(done) {
request(app).get("/").expect(200).end(done);
});
(...)
it("GETS dictionary-api", function(done) {
request(app).get("/dictionary-api").expect(200).end(done);
});
it("POSTS dictionary-api", function(done) {
request(app).post("/dictionary-api")
.send({ "term":"Three", "defined":"Term three defined"})
.expect(200)
.end(done);
});
it("DELETES dictionary-api", function(done) {
request(app).delete("/dictionary-api/One")
.expect(200)
.end(done);
});
njsetn/testing_http_endpoints_with_supertest.txt · Last modified: 2016/03/28 17:03 by leo