- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我需要一些帮助来解决我对 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/
我正在使用 supertest 发送获取查询字符串参数,我该怎么做? 我试过 var imsServer = supertest.agent("https://example.com"); imsSe
我正在使用 expressjs 构建 API,我的路线如下所示 module.exports = function(app){ var book = require('../controllers/b
我是测试驱动开发的新手,正在尝试使用 super 测试来自学。我很困惑为什么我不断收到错误“应用程序未定义”?这是我对 request(app) 的调用,我在下面用粗体显示了它。我尝试查找文档,但似乎
初学者使用 Javascript 进行测试。我正在使用摩卡,但路易斯明智地表示,这个问题并不是摩卡特有的。我有一个 Node 应用程序,其中一些页面对匿名用户可见,而有些页面如果您未登录,则不应该看到
我正在尝试用 typescript 编写 API 测试。 我已经像这样安装了以下软件包: npm install -g mocha npm install chai npm install super
我有以下服务器类: import express, { Request, Response } from 'express'; export default class Server { serv
我正在使用 express 开发一个 API 并使用 supertest 对其进行测试.我的 API 端点正在返回 tar.gz 文件。我想测试一下文件是否正确发送并且内容是否正确。我在弄清楚如何检索
我是后端开发的新手,我遇到了一个我不明白的问题。 我设置了名为“health”的 API 的第一个路由,它只返回一条简单消息以了解我的服务器是否已启动。 这条路线看起来像预期的那样工作。 但是, 当我
我懂了 TypeError: Cannot read property 'status' of undefined 当尝试使用 supertest 将文件上传到简单的 Restify 服务器时,并且打
用supertest,我可以测试重定向代码302 var request = require('supertest'); var app = require('../server').app; des
我正在使用 supertest 测试我的 API 端点,而且效果很好,但我不知道如何测试文件下载是否成功。 在我的路由文件中,我将端点定义为: app.get('/api/attachment/:id
当我进行 API 调用时,我想检查返回的 JSON 的结果。我可以看到正文和一些静态数据正在被正确检查,但是在我使用正则表达式的任何地方,事情都被破坏了。这是我的测试示例: describe('get
我无法运行多个 Supertest/Mocha 测试,因为出现错误 Error: Trying to open unclosed connection. - 我发现了这个 post这建议循环并检查连接
我有一个使用 multer 并获取文件数组的 post 端点: router.post('/api/projects/:id/sessions', upload.array('files', 4),
我有一个经过 Mocha 测试的应用程序,并且能够使用我现在拥有的内容成功运行测试,但我在测试文件中显式设置了到 /api/v1 的 GET 路由。这是测试文件... API.js: var requ
我在 supertest、mocha 和 Node 方面遇到了一些问题,解析状态代码为 400。 这是我的 index.js 代码: var express = require('express');
我希望能够获取一些响应属性,并有时使用 SuperTest 将它们放入变量中。我怎样才能做到这一点?除了对响应的断言之外,我没有看到文档执行任何操作。 例如我想做这样的事情: var statusC
下面的数组(query.conditions)以某种方式转换为对象,知道为什么以及如何防止它吗? 请求: supertest(options.url) .g
我有一个看起来像这样的测试: it('should fail to get deleted customer', function(done) { request(app) .
我正在使用 supertest 测试我的 NodeJS 应用程序.我的应用程序正在请求证书,我的用户获得了针对该应用程序的授权证书的 CN。 在测试我的第一条路线时,我收到一个错误,提示我的自签名证书
我是一名优秀的程序员,十分优秀!