Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js TypeError:即使我正在导出服务器,app.address也不是一个函数_Node.js_Express_Supertest - Fatal编程技术网

Node.js TypeError:即使我正在导出服务器,app.address也不是一个函数

Node.js TypeError:即使我正在导出服务器,app.address也不是一个函数,node.js,express,supertest,Node.js,Express,Supertest,当我试图在我的快速路线上运行单元测试时,我得到了标题中显示的TypeError,我发现了另外3个类似的问题,但这些问题的解决方案并不能解决我的问题。我需要一些其他可能的解决办法 错误 ? Compliance requests > /v1/healthcheck TypeError: app.address is not a function at Test.Object.<anonymous>.Test.serverAddress (node_modu

当我试图在我的快速路线上运行单元测试时,我得到了标题中显示的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)
healthcheck.js(测试)

healthcheck.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
// 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')
    })
})
// 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
//这是我正在测试的路线
const express=require('express')
const router=express.router()
const{currentVersion}=require(“../constants”)
router.get(`/${currentVersion}/healthcheck`,(req,res)=>{
res.end(`${process.env.HEALTHMESSAGE}`)
})
module.exports=路由器

小字体-哦,对不起-打字错误:D


module.export
而不是
module.export

小字体-哦,对不起-打字错误:D


module.exports
而不是
module.export

它是
module.exports
而不是
module.export
OMG。真不敢相信我在这上面花了多少时间。请回答这个问题,我会接受的。它是
module.exports
而不是
module.export
OMG。真不敢相信我在这上面花了多少时间。请回答这个问题,我会接受的。非常感谢。非常感谢。