- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在玩 vows 和 nodejs。
var vows = require('vows');
var http = require('http');
var suite = vows.describe('testing');
var host = 'www.google.com', port = '80', path = '/', method = 'GET';
suite.addBatch({
'A context': {
topic: function(){
http.get({
host: host,
port: port,
path: path,
method: method
}, this.callback);
},
"sample test": function(res, extra){//here extra is just to prevent vows error
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);//It never gets logged
});
console.log('HEADERS: ' + JSON.stringify(res.headers));//it is working
}
}
});
suite.export(module);
但是我无法获取响应正文。我做错了什么。
我正在使用 nodejs v 0.6.6 和 vows v0.6.2
最佳答案
据我所知,当 this.callback
运行时,Vows 似乎没有直接调用测试。它被 processnextTick
延迟。如果非要我猜的话,也许“数据”事件是在那段时间发出的。这意味着在触发所有数据事件之前,您不会绑定(bind)“数据”函数。
但实际上,问题是 Vows 测试应该将像这样的所有异步逻辑分离到 topic
本身。如果你真的想检查测试中的 block ,那么就这样做吧。
另请注意,您可以拥有任意数量的 block ,而不仅仅是单个 data
事件。您可能想要设置流编码,并将数据作为字符串加入。您当前的代码将 Buffer 隐式转换为字符串,这可能会中断多字节字符。
suite.addBatch({
'A context': {
topic: function(){
var cb = this.callback;
var req = http.get({
host: host,
port: port,
path: path,
method: method
});
// Aggregate all chunks before running callback
req.on('response', function(res) {
var chunks = []
res.on('data', function(chunk) {
chunks.push(chunk);
});
res.on('end', function() {
cb(null, res, chunks);
});
});
// Handle connection failures.
req.on('error', cb);
},
"sample test": function(err, res, chunks){
chunks.forEach(function (chunk, i) {
console.log('BODY piece ' + i + ': ' + chunk);
});
console.log('HEADERS: ' + JSON.stringify(res.headers));
}
}
});
关于node.js - Node : Unable to get response body when working with vows and nodejs http module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463580/
我有一个如下的测试文件: // Dependencies var Vows = require("vows") , Request = require("request") , Assert
我在将父 topic 值传递给子 topic 值时遇到问题。该代码是异步的,我认为这就是我遇到问题的地方。我希望 JSON 响应的一部分成为下面测试的主题。这是测试的相关部分。 { "A test
我有一个 express 服务器,我正在使用 vows 进行测试。我想从 vows 测试套件中运行服务器,这样我就不需要让它在后台运行以使测试套件工作,然后我可以创建一个运行服务器并对其进行测试的蛋糕
我希望我的誓言能够从我的主题访问 outerDocs 和 innerDocs,但它没有。 'ASYNC TOPIC': { topic: function() { aModel.find(
我一直在使用 node 并使用 vows 编写测试。 var vows = require('vows'); var assert = require('assert'); var boardData
我花了一些时间在 NodeJS 测试套件中调试一个奇怪的无限循环问题。它只在极少数情况下发生,但我可以在附加到 chrome 调试器时重现它。 我认为这与 V8 对 stack traces in e
来自誓言网站:“当调用 this.callback 时,它将收到的参数一一传递给测试函数,就好像这些值是由主题函数本身返回的一样。”换句话说,如果我们使用请求库来处理我们的 http 请求,我们的主题
我正在使用 Vows.js 测试一些在数据库中创建记录的 node.js。结果,它在数据库中创建了一些测试记录。测试运行后,我想删除这些记录。有没有办法在 Vows 中运行一批测试时运行清理功能? 最
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试为我的普通 Express 应用程序编写一些基于 Vows 的测试。 这是测试源: var vows = require('vows'); var assert = require('ass
假设我有以下序列: vows.describe('Example').addBatch({ 'An example' : { topic: new Example(),
对于整个 node.js 社区来说都是新手,我在我的第一个应用程序上进行单元测试时遇到了问题。问题是它们通过了,但它们实际上从未在回调中运行断言。据我了解, Mongoose (我用来与 MongoD
Vows 有一个 run() 方法,可以在 Node 下运行测试,而无需使用 vows 命令。 在 https://github.com/cloudhead/vows/blob/master/lib/
我正在尝试决定是否为大型 Node 应用程序从 Vows 切换到 Mocha。 我享受了几乎所有的 Vows 体验 - 但争论的传递有点奇怪。我总是不得不挠头来记住主题是如何工作的,这会干扰编写测试的
我目前正在 Node/amqp 应用程序中使用 Q promise 库。我读过 Q 与 BlueBird 或 Vow 等库的性能……不太好。 不幸的是,我不知道如何使用 BlueBird(或 Vow)
在测试我在 node.js 中创建的 RESTful api 时,我真的可以接受一些建议。那里有太多的框架,我不知所措。我的测试知识通常不够好,这就是我尝试编写这些测试的原因。我试过 vows.js,
我对 Node.js 测试完全陌生,也许你可以帮助我:我想使用誓言和托比为我的 Express Web 应用程序做一些或多或少的简单测试(例如测试登录路由是否有效) var vows = requ
我在如何使用 Vows 正确构建 Promise-returning API 测试方面遇到了困难,例如 topic:function() { return myfunc() { /* returns
我花了很多时间尝试让基本的 http 测试与 vows 一起工作。 我想我已经遵循了 vows http://vowsjs.org/#-writing-asynchronous-tests 中的异步示
我正在尝试开始使用 Vows和 Vows-BDD .不幸的是,回调让我绊倒了。 在下面这个非常简单的例子中,如何修复这个错误? ** Inside the first context ** Creat
我是一名优秀的程序员,十分优秀!