Search code examples
mongoosesupertest

connect ECONNREFUSED 127.0.0.1:80 error only on one test of supertest


I read a similar issue on github and my case is a bit different

I have 12 passing tests, but the one below keeps throwing connect ECONNREFUSED 127.0.0.1:80

It's the only one that uses del so maybe that's the problem?

describe('deleteOne', () => {
  it('should delete task', async done => {
    const { token } = await createUser()
    const { _id } = await createTask(token)
    const res = await request(app)
      .del(`api/tasks/${_id}`)
      .set('authorization', 'Bearer ' + token)
    expect(res.statusCode).toEqual(204)
    done()
  })
})

Solution

  • I have encountered the same error. Notice the url that you're sending the request to api/tasks/${_id} there should be a backslash at the beginning /api/tasks/${_id}. That should fix it