node.js - Why is address undefined in my app? -
i have 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 running on port: ' + port); }); }; exports.start = start; and integration test:
var request = require('supertest'); var app = require('../app'); describe('get /', function(){ it('should repsond 200', function(done){ request(app) .get('/') .expect(200, done.fail); }); }); the app runs fine, running integration test, following error:
failures: 1) / should repsond 200 1.1) typeerror: object #<object> has no method 'address' i did searching , seems if app wasn't exported correctly can't seem figure out why.
request(app.app) instead of request(app) in integration test should fix error.
var request = require('supertest'); var app = require('../app'); describe('get /', function(){ it('should repsond 200', function(done){ request(app.app) .get('/') .expect(200, done.fail); }); });
Comments
Post a Comment