{"action":"created","issue":{"url":"https://api.github.com/repos/visionmedia/supertest/issues/497","repository_url":"https://api.github.com/repos/visionmedia/supertest","labels_url":"https://api.github.com/repos/visionmedia/supertest/issues/497/labels{/name}","comments_url":"https://api.github.com/repos/visionmedia/supertest/issues/497/comments","events_url":"https://api.github.com/repos/visionmedia/supertest/issues/497/events","html_url":"https://github.com/visionmedia/supertest/issues/497","id":349475428,"node_id":"MDU6SXNzdWUzNDk0NzU0Mjg=","number":497,"title":"Mocha Supertest Express: app.address is not a function even if I exported correctly app.","user":{"login":"Danver97","id":28715404,"node_id":"MDQ6VXNlcjI4NzE1NDA0","avatar_url":"https://avatars3.githubusercontent.com/u/28715404?v=4","gravatar_id":"","url":"https://api.github.com/users/Danver97","html_url":"https://github.com/Danver97","followers_url":"https://api.github.com/users/Danver97/followers","following_url":"https://api.github.com/users/Danver97/following{/other_user}","gists_url":"https://api.github.com/users/Danver97/gists{/gist_id}","starred_url":"https://api.github.com/users/Danver97/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Danver97/subscriptions","organizations_url":"https://api.github.com/users/Danver97/orgs","repos_url":"https://api.github.com/users/Danver97/repos","events_url":"https://api.github.com/users/Danver97/events{/privacy}","received_events_url":"https://api.github.com/users/Danver97/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-10T11:10:47Z","updated_at":"2018-08-15T04:44:02Z","closed_at":null,"author_association":"NONE","body":"Good morning.\r\nI'm still considering quite a newbe in Node.Js since very often I get into problems that with a bit of searching I figure out how to solve. Except this.\r\n\r\nThis is my `./src/app.js` file:\r\n```javascript\r\nconst express = require('express');\r\nconst bodyParser = require('body-parser');\r\nconst ENV = require('./env');\r\nconst request = require('supertest');\r\nconst app = express();\r\n\r\napp.use(bodyParser.json());\r\napp.use(bodyParser.urlencoded({ extended: false }));\r\n\r\napp.get('/', (req, res) => {\r\n    res.json({\r\n        service: 'user-service',\r\n    });\r\n});\r\n\r\n// This works correctly\r\nconst req = request(app);\r\nreq\r\n    .get('/')\r\n    .expect('Content-Type', /json/)\r\n    .expect(JSON.stringify({\r\n        service: 'user-service'\r\n    }))\r\n    .expect(200)\r\n    .end(function (err, res) {\r\n        if (err) throw err;\r\n    });\r\n\r\n// I tired in both ways\r\nmodule.exports = Object.assign({}, app);\r\n// module.exports = app;\r\n```\r\n\r\nThis is my `./index.js` file:\r\n```javascript\r\nconst app = require('./src/app');\r\nconst ENV = require('./src/env');\r\n\r\napp.listen(3000, () => {\r\n    console.log(`Server started on port ${ENV.port}`);\r\n});\r\n\r\nmodule.exports = app;\r\n```\r\n\r\nThis is my `./test/test.js` file:\r\n```javascript\r\nconst request = require('supertest');\r\nconst app = request('../src/app');\r\n/*\r\n  using request('http://localhost:3000') works correctly\r\n  but i know it's not the best way to setup a testing environment\r\n*/\r\n//const req = request('http://localhost:3000'); \r\nconst req = request(app);\r\n\r\ndescribe('Integration test exaple', function() {\r\n    it('get /', function(done) {\r\n        req\r\n        .get('/')\r\n        .expect('Content-Type', /json/)\r\n        .expect(JSON.stringify({ service: 'user-service' }))\r\n        .expect(200, done);\r\n    });\r\n});\r\n```\r\n\r\nI tried to require `app` both from `app.js` and `index.js` but the result it's the same:\r\n```shell\r\n>> mocha ./test/test\r\n\r\n  Integration test exaple\r\n    1) get /\r\n\r\n  0 passing (9ms)\r\n  1 failing\r\n\r\n  1) Integration test exaple\r\n       get /:\r\n     TypeError: app.address is not a function\r\n      at Test.serverAddress (node_modules\\supertest\\lib\\test.js:55:18)\r\n      at new Test (node_modules\\supertest\\lib\\test.js:36:12)\r\n      at Object.obj.(anonymous function) [as get] (node_modules\\supertest\\index.js:25:14)\r\n      at Context.<anonymous> (test\\integration.test.js:12:10)\r\n```\r\n\r\nThanks in advance for any kind of help!"},"comment":{"url":"https://api.github.com/repos/visionmedia/supertest/issues/comments/413092791","html_url":"https://github.com/visionmedia/supertest/issues/497#issuecomment-413092791","issue_url":"https://api.github.com/repos/visionmedia/supertest/issues/497","id":413092791,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzA5Mjc5MQ==","user":{"login":"jonathansamines","id":1268268,"node_id":"MDQ6VXNlcjEyNjgyNjg=","avatar_url":"https://avatars0.githubusercontent.com/u/1268268?v=4","gravatar_id":"","url":"https://api.github.com/users/jonathansamines","html_url":"https://github.com/jonathansamines","followers_url":"https://api.github.com/users/jonathansamines/followers","following_url":"https://api.github.com/users/jonathansamines/following{/other_user}","gists_url":"https://api.github.com/users/jonathansamines/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathansamines/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathansamines/subscriptions","organizations_url":"https://api.github.com/users/jonathansamines/orgs","repos_url":"https://api.github.com/users/jonathansamines/repos","events_url":"https://api.github.com/users/jonathansamines/events{/privacy}","received_events_url":"https://api.github.com/users/jonathansamines/received_events","type":"User","site_admin":false},"created_at":"2018-08-15T04:44:02Z","updated_at":"2018-08-15T04:44:02Z","author_association":"NONE","body":"@Danver97 Exporting ´Object.assign({}, app)´ would never work because it will convert your `app` (which is a function) into an object. Are you sure it isn't working by just exporting the app instance? \r\n\r\nBesides that, you can alternatively export the result of `app.listen` from your index file to export the Http server instance, which should work as expected on your integration test\r\n\r\nHope it helps."}}
{"actor":{"display_login":"jonathansamines"}}