Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why this test fails while testing my api endpoint?

this error

Uncaught exception: Error: listen EADDRINUSE: address already in use :::3000

import supertest from "supertest"
import axios from "axios"
import app from ".."
const request = supertest(app)

describe("Test endpoint responses", () => {
    it("gets the api endpoint", async () => {
      const response = await request.get("/api/images")
       expect(response.ok).toBe(false)
    })
})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This means that the port 3000 of the machine that is executing the test is already used. As a general rule, a port cannot be used by multiple application at the same time.

In your case, you probably already have another test running, or a local development server running on this port.

You can either stop it, or configure your test runner to use a different port.

EDIT 1 :

As mentioned by chovy in comment, you can prepend your command with PORT=3001

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading