'Error Supertest - got 404 "Not Found on expect method when using supertest module

I'm doing a simple automation test with supertest and receiving an error :

expected 400 "Bad Request", got 404 "Not Found"

When I google this error, I have found a stackoverflow link with the same issue. By reading the article, my application is meeting the requirements which is isolate the express app from app.listen in index.js.

Here is the link: Stackoverflow

Development dependencies that I'm using are the following:

"devDependencies": {
    "@types/jest": "^27.4.1",
    "@types/supertest": "^2.0.12",
    "jest": "^27.5.1",
    "supertest": "^6.2.2"
  }

Test code:

const app = require("../../express-app");
const { StatusCodes } = require("http-status-codes");
const request = require("supertest");
const { fakeUserData, invalidEmail } = require("../../database/fixtures");


describe("Testing Signup", () => {
  it("returns a 201 on successful signup", async () => {
    return request(app)
      .post("/signup")
      .send(fakeUserData)
      .expect(StatusCodes.CREATED);
  });
});

Typescript configuration file:

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "types": [
      "jest",
      "supertest"
    ],
"allowJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
},
  "include": ["./src/**/*", "./src/tests/**/*.utils.js"],
  "exclude": ["./node_modules"]
}

Please I want to know if there is a bug in supertest OR what I'm doing wrong???



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source