gpt4 book ai didi

node.js - 类型错误 : Cannot read property 'address' of undefined supertest

转载 作者:IT老高 更新时间:2023-10-28 23:14:33 26 4
gpt4 key购买 nike

我需要一些帮助来解决我对 nodejs 代码进行测试的问题。我正在使用 Mocha 和 super 测试。我对超测中的实现感到困惑。我不知道要解决它。我正在尝试自动下载文件。

describe('GET /entry/:entryId/file/:id/download', function(){
it('should pass download function', function(done){
this.timeout(15000);
request(app.webServer)
.get('/entry/543CGsdadtrE/file/wDRDasdDASAS/download')
.set('Authorization', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGco')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
console.log(err, res);
done();
});
});
});

最佳答案

在测试 express 应用时,我从 mocha 收到了类似的错误。错误全文:

0 passing (185ms)
2 failing

1) loading express responds to /:
TypeError: app.address is not a function
at Test.serverAddress (test.js:55:18)
at new Test (test.js:36:12)
at Object.obj.(anonymous function) [as get] (index.js:25:14)
at Context.testSlash (test.js:12:14)

2) loading express 404 everything else:
TypeError: app.address is not a function
at Test.serverAddress (test.js:55:18)
at new Test (test.js:36:12)
at Object.obj.(anonymous function) [as get] (index.js:25:14)
at Context.testPath (test.js:17:14)

我通过将它添加到我的 express server.js 来修复它,即导出服务器对象

module.exports = app

关于node.js - 类型错误 : Cannot read property 'address' of undefined supertest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37044289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com