Search code examples
node.jsjasminesupertest

Why my endpoint testing function doesn't work?


I get weird error whenever i'm testing my endpoint through jasmine and superset.

import app from '../index'
import supertest from 'supertest'

const request = supertest(app);

describe("suite for testing the image endpoint response", () => {
    //done for supertest to tell when our endpoint is done to disconnect from server
    it('Server is up',  async (done)=>{
        const response =  await request.get('api/image');
        expect(response.status).toBe(200);
        done();
    })
})

The Error:

  1. suite for testing the image endpoint response Server is up
  • An asynchronous before/it/after function took a done callback but also returned a promise. Either remove the done callback (recommended) or change the function to not return a promise. thrown
  • Unhandled promise rejection: Error: ECONNREFUSED: Connection refused
  • Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

Executed 1 of 1 spec (1 FAILED) in 5 secs.

I tried to remove "done()" which is wrong to be removed since it closes the connection after the test, but still same error.


Solution

  • By removing done in parameters and done() in the last line, will make it work.