异步主题范围Vows.JS
Asynchronous Topic Scope Vows.JS
我在将父topic
值传递给子topic
值时遇到问题。代码是异步的,我认为这就是我的问题所在。我希望JSON响应的一部分成为下面测试的主题。以下是测试的相关部分。
{
"A test":{
topic: function() {
request(conf.server + '/categories/' + id, this.callback)
},
'should respond with a 200': function(err, res, body) {
res.statusCode.should.equal(200);
console.log(JSON.parse(body).title);
},
'should have valid JSON in the body': function(err, res, body) {
(function() {
JSON.parse(body);
}).should.not.
throw();
},
'category collection': {
topic: function(err, res, body) {
console.log(res.statusCode);
return JSON.parse(body).categories
},
'should have a length greater than 0': function(topic) {
topic.length.should.be.above(0);
}
}
}
}
console.log(res.statusCode)
产生未定义的结果,并且尝试将topic
记录在"应该具有大于0的长度"中会产生[SyntaxError: Unexpected token u]
。
我能做这个吗?如果是,如何?
我对此进行了快速测试,似乎当第一个参数err为null时,它不会传递到子上下文。将传递所有其他参数。这是我的密码。:
module.exports = ( function() {
var vows = require('vows'), assert = require('assert'), suite;
suite = vows.describe('Vows test');
suite.addBatch({
'Parent context ' : {
topic : function() {
this.callback(null, "first", "second");
},
'err should be null' : function(err, first, second) {
assert.isNull(err);
assert.isNotNull(first);
assert.isNotNull(second);
},
'subcontext: ' : {
topic : function(err, first, second) {
console.log('Err: ' + err + ', first: ' + first + ', second: ' + second);
this.callback(null, "firstChild");
},
'Error should be null' : function(err, firstChild) {
assert.isNull(err);
assert.isNotNull(firstChild);
}
}
}
});
suite.run();
}());
结果为CCD_ 6。
但当我传递错误的东西时,日志甚至并没有打印出来,并且出现子上下文错误。
我不知道具体的原因。我会检查誓言代码,如果我发现什么就回来。希望这对你有用。
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 使用agility.js进行页面布局和合成
- 使用Clipboard.js复制span文本
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 强制模板刷新ember.js
- 如何编写HTML输入的JS内联
- Angular JS IE9 Hashbang url rewriting
- 使用JS将数组转换为json对象
- Node.js v6.2.0类扩展不是函数错误
- 当js函数's已执行
- 要求未定义JS回调参数
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 如何从Java/scala调用js美化程序
- 如何更改<svg>标记为<img>用js标记
- 如何使用 node.js 比较两个 json 数组
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 如何为异步递归操作编写 vows js bdd 测试
- 写入异步Vows.js测试时出错
- 异步主题范围Vows.JS