|
1 | 1 | const request = require("supertest");
|
2 | 2 | const app = require("./testing_example_1");
|
3 | 3 |
|
4 |
| -describe("GET /", () => { |
5 |
| - it("should respond correctly", async done => { |
6 |
| - const response = await request(app) |
7 |
| - .get("/") |
8 |
| - .expect(200); |
9 |
| - expect(response.text).toEqual("Welcome to my homepage"); |
10 |
| - done(); |
11 |
| - }); |
| 4 | +describe("testing example 1", () => { |
| 5 | + describe("GET /", () => { |
| 6 | + it("should respond correctly with success code", async done => { |
| 7 | + const response = await request(app) |
| 8 | + .get("/") |
| 9 | + .expect(200); |
| 10 | + expect(response.text).toEqual("Welcome to my homepage"); |
| 11 | + done(); |
| 12 | + }); |
12 | 13 |
|
13 |
| - it("should respond correctly", async done => { |
14 |
| - const { text } = await request(app) |
15 |
| - .get("/") |
16 |
| - .expect(200); |
17 |
| - expect(text).toEqual("Welcome to my homepage"); |
18 |
| - done(); |
| 14 | + it("should respond correctly with success code", async done => { |
| 15 | + const { text } = await request(app) |
| 16 | + .get("/") |
| 17 | + .expect(200); |
| 18 | + expect(text).toEqual("Welcome to my homepage"); |
| 19 | + done(); |
| 20 | + }); |
19 | 21 | });
|
20 |
| -}); |
21 | 22 |
|
22 |
| -describe("GET /books", () => { |
23 |
| - it("should respond correctly", async done => { |
24 |
| - const response = await request(app) |
25 |
| - .get("/books") |
26 |
| - .expect(200); |
27 |
| - expect(response.text).toEqual("You requested a list of books...."); |
28 |
| - done(); |
29 |
| - }); |
| 23 | + describe("GET /books", () => { |
| 24 | + it("should respond correctly with success code", async done => { |
| 25 | + const response = await request(app) |
| 26 | + .get("/books") |
| 27 | + .expect(200); |
| 28 | + expect(response.text).toEqual("You requested a list of books...."); |
| 29 | + done(); |
| 30 | + }); |
30 | 31 |
|
31 |
| - it("should get a book by id", async done => { |
32 |
| - const id = "3"; |
33 |
| - const response = await request(app) |
34 |
| - .get(`/books/${id}`) |
35 |
| - .expect(200); |
36 |
| - expect(response.text).toEqual(`You request information on book ${id}`); |
37 |
| - done(); |
| 32 | + it("should get a book by id", async done => { |
| 33 | + const id = "3"; |
| 34 | + const response = await request(app) |
| 35 | + .get(`/books/${id}`) |
| 36 | + .expect(200); |
| 37 | + expect(response.text).toEqual(`You request information on book ${id}`); |
| 38 | + done(); |
| 39 | + }); |
38 | 40 | });
|
39 |
| -}); |
40 | 41 |
|
41 |
| -describe("POST /", () => { |
42 |
| - it("should respond correctly when sending json", async done => { |
43 |
| - const { text } = await request(app) |
44 |
| - .post("/") |
45 |
| - .send({ thisIsJson: "json!" }) |
46 |
| - .expect(200); |
47 |
| - expect(text).toEqual("Thanks for the JSON!"); |
48 |
| - done(); |
49 |
| - }); |
| 42 | + describe("POST /", () => { |
| 43 | + it("should respond correctly when sending json", async done => { |
| 44 | + const { text } = await request(app) |
| 45 | + .post("/") |
| 46 | + .send({ thisIsJson: "json!" }) |
| 47 | + .expect(200); |
| 48 | + expect(text).toEqual("Thanks for the JSON!"); |
| 49 | + done(); |
| 50 | + }); |
50 | 51 |
|
51 |
| - it("should respond with status 400 and correct string when sending non-json", async done => { |
52 |
| - const { text } = await request(app) |
53 |
| - .post("/") |
54 |
| - .send("This is not json!") |
55 |
| - .expect(400); |
56 |
| - expect(text).toEqual("Server wants application/json!"); |
57 |
| - done(); |
| 52 | + it("should respond with status 400 and correct string when sending non-json", async done => { |
| 53 | + const { text } = await request(app) |
| 54 | + .post("/") |
| 55 | + .send("This is not json!") |
| 56 | + .expect(400); |
| 57 | + expect(text).toEqual("Server wants application/json!"); |
| 58 | + done(); |
| 59 | + }); |
58 | 60 | });
|
59 | 61 | });
|
0 commit comments