Skip to content

Commit f683f02

Browse files
[mabel] Minor edits to testing example 1 and test
1 parent 37128ab commit f683f02

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

testing_example_1.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const express = require("express");
22
const app = express();
3-
const PORT = 3000;
43

54
app.get("/", (req, res) => {
65
res.send("Welcome to my homepage");

testing_example_1.test.js

+49-47
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,61 @@
11
const request = require("supertest");
22
const app = require("./testing_example_1");
33

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+
});
1213

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+
});
1921
});
20-
});
2122

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+
});
3031

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+
});
3840
});
39-
});
4041

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+
});
5051

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+
});
5860
});
5961
});

0 commit comments

Comments
 (0)