File tree 1 file changed +23
-2
lines changed
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
1
const request = require ( "supertest" ) ;
2
2
const app = require ( "../../app" ) ;
3
3
4
- describe ( "Test route /article" , ( ) => {
4
+ describe ( "Test GET /article" , ( ) => {
5
5
test ( "It should response 200 on GET method" , done => {
6
6
request ( app )
7
7
. get ( "/article" )
@@ -10,4 +10,25 @@ describe("Test route /article", () => {
10
10
done ( ) ;
11
11
} ) ;
12
12
} ) ;
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments