Skip to content

Commit a6dd6bf

Browse files
committed
BE #4 functional test for POST method
1 parent 3cb500e commit a6dd6bf

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/routes/article.test.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const request = require("supertest");
22
const app = require("../../app");
33

4-
describe("Test route /article", () => {
4+
describe("Test GET /article", () => {
55
test("It should response 200 on GET method", done => {
66
request(app)
77
.get("/article")
@@ -10,4 +10,25 @@ describe("Test route /article", () => {
1010
done();
1111
});
1212
});
13-
});
13+
});
14+
15+
16+
const article = {
17+
title: "Test: how to test express API POST request?",
18+
body: ["<h2>Article body sub heading</h2>","<p>Article body paragraph</p>"]
19+
};
20+
21+
/* POST /article */
22+
describe("Test POST /article", () => {
23+
test("It should response 200 on POST method", done => {
24+
request(app)
25+
.post("/article")
26+
.send(article)
27+
.then(response => {
28+
const respArticle=JSON.parse(response.text);
29+
expect(response.statusCode).toBe(200);
30+
expect(respArticle.title).toBe(article.title);
31+
done();
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)