Step 3

Let's write a simple test!

Create a tests subfolder at the root of the repository.

Next, add index.test.js file to the tests folder:

const supertest = require("supertest");
const app = require("../server");

const request = supertest(app);

test("Get 200 for API homepage", async () => {
  const response = await request.get("/");
  expect(response.status).toBe(200);
});

Next, update the scripts in package.json:

-  "test": "echo \"Error: no test specified\" && exit 1"
+  "test": "jest"

Finally, run the test:

npm run test

You should see an output similar to this: