Why is address undefined in my app?

2.3k views Asked by At

I have a simple express app:

var express = require('express');
var path = require('path');

var app = express();
exports.app = app;

var index = require('./routes/index');

app.use(express.static(path.join(__dirname,'client/dist/')));

app.get('/', index.get);

function start(){
    var port = process.env.PORT || 8080;

    app.listen(port, function(){
        console.log('app is running on port: ' + port);
    });
};

exports.start = start;

And an integration test:

var request = require('supertest');

var app = require('../app');

describe('GET /', function(){
    it('should repsond with 200', function(done){
        request(app)
        .get('/')
        .expect(200, done.fail);
    });
});

The app runs fine, but running the integration test, I get the following error:

Failures: 
1) GET / should repsond with 200
1.1) TypeError: Object #<Object> has no method 'address'

I did some searching and it seems as if app wasn't exported correctly but I can't seem to figure out why.

1

There are 1 answers

0
Sushil On BEST ANSWER

request(app.app) instead of request(app) in integration test should fix the error.

var request = require('supertest');
var app = require('../app');

describe('GET /', function(){
  it('should repsond with 200', function(done){
      request(app.app)
      .get('/')
      .expect(200, done.fail);
  });
});