TypeError: app.address is not a function even though I am exporting my server
TypeError: app.address is not a function even though I am exporting my server
我在尝试对我的快速路线进行 运行 单元测试时遇到标题中显示的 TypeError 我发现了其他 3 个类似的问题,但这些问题的解决方案并没有解决我的问题。我需要一些其他可能的解决方案。
错误
? Compliance requests > /v1/healthcheck
TypeError: app.address is not a function
at Test.Object.<anonymous>.Test.serverAddress (node_modules/supertest/lib/test.js:55:18)
at new Test (node_modules/supertest/lib/test.js:36:12)
at Object.obj.(anonymous function) [as get] (node_modules/supertest/index.js:25:14)
at Object.it (__tests__/routes/healthcheck.js:7:9)
at new Promise (<anonymous>)
at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
Compliance requests
x /v1/healthcheck (3ms)
App.js
// this is the app.js I am using for my test routes
const express = require('express')
const app = express()
const translation = require('../routes/translation')
const healthcheck = require('../routes/healthcheck')
// routes
app.use(translation)
app.use(healthcheck)
const port = process.env.PORT || 3100 // set our port
let server = app.listen(port, () => {
var host = server.address().address;
var port = server.address().port;
console.log('CHATS is listening at http://%s:%s', host, port);
});
module.export = server
healthcheck.js(测试)
// This is my test
const request = require('supertest')
const app = require('../../__test-config/app')
describe('Compliance requests', () => {
it('/v1/healthcheck', async () => {
const res = await request(app)
.get('/v1/healthcheck')
.expect(200)
expect(res.body).toContain('CHATS IS HEALTHY')
})
})
healthcheck.js
// This is route I am testing
const express = require('express')
const router = express.Router()
const { currentVersion } = require('../constants')
router.get(`/${currentVersion}/healthcheck`, (req, res) => {
res.end(`<html><body><h3>${process.env.HEALTHMESSAGE}</h3></body></html>`)
})
module.exports = router
小字体 - 哦抱歉 - 打字错误。 :D
module.exports
而不是 module.export
我在尝试对我的快速路线进行 运行 单元测试时遇到标题中显示的 TypeError 我发现了其他 3 个类似的问题,但这些问题的解决方案并没有解决我的问题。我需要一些其他可能的解决方案。
错误
? Compliance requests > /v1/healthcheck
TypeError: app.address is not a function
at Test.Object.<anonymous>.Test.serverAddress (node_modules/supertest/lib/test.js:55:18)
at new Test (node_modules/supertest/lib/test.js:36:12)
at Object.obj.(anonymous function) [as get] (node_modules/supertest/index.js:25:14)
at Object.it (__tests__/routes/healthcheck.js:7:9)
at new Promise (<anonymous>)
at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
Compliance requests
x /v1/healthcheck (3ms)
App.js
// this is the app.js I am using for my test routes
const express = require('express')
const app = express()
const translation = require('../routes/translation')
const healthcheck = require('../routes/healthcheck')
// routes
app.use(translation)
app.use(healthcheck)
const port = process.env.PORT || 3100 // set our port
let server = app.listen(port, () => {
var host = server.address().address;
var port = server.address().port;
console.log('CHATS is listening at http://%s:%s', host, port);
});
module.export = server
healthcheck.js(测试)
// This is my test
const request = require('supertest')
const app = require('../../__test-config/app')
describe('Compliance requests', () => {
it('/v1/healthcheck', async () => {
const res = await request(app)
.get('/v1/healthcheck')
.expect(200)
expect(res.body).toContain('CHATS IS HEALTHY')
})
})
healthcheck.js
// This is route I am testing
const express = require('express')
const router = express.Router()
const { currentVersion } = require('../constants')
router.get(`/${currentVersion}/healthcheck`, (req, res) => {
res.end(`<html><body><h3>${process.env.HEALTHMESSAGE}</h3></body></html>`)
})
module.exports = router
小字体 - 哦抱歉 - 打字错误。 :D
module.exports
而不是 module.export