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.
request(app.app)
instead ofrequest(app)
in integration test should fix the error.