TypeError: Cannot read property address' w90> supertest

I need help to solve my problem with testing on nodes. I use mocha and supertest. I am confused with the implementation in a super test. I do not know how to solve this. I am trying to automate a file upload.

`describe('GET /entry/:entryId/file/:id/download', function(){ it('should pass download function', function(done){ this.timeout(15000); request(app.webServer) .get('/entry/543CGsdadtrE/file/wDRDasdDASAS/download') .set('Authorization', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGco') .expect(200) .end(function(err, res){ if (err) return done(err); console.log(err, res); done(); }); }); }); 
+8
mocha supertest
source share
2 answers

I got a similar error from moka when testing express applications. Full error text:

 0 passing (185ms) 2 failing 1) loading express responds to /: TypeError: app.address is not a function at Test.serverAddress (test.js:55:18) at new Test (test.js:36:12) at Object.obj.(anonymous function) [as get] (index.js:25:14) at Context.testSlash (test.js:12:14) 2) loading express 404 everything else: TypeError: app.address is not a function at Test.serverAddress (test.js:55:18) at new Test (test.js:36:12) at Object.obj.(anonymous function) [as get] (index.js:25:14) at Context.testPath (test.js:17:14) 

I fixed this by adding this to my express server. js, i.e. exports a server object

 module.exports = app 
+9
source share

Typescript users who encounter this error, check two things:

  • The express server should have module.exports = app (thanks to @Collin D )
  • Use import * as app from "./app"
    instead of the wrong import app from "./app"
+3
source share