【发布时间】:2013-02-06 17:42:39
【问题描述】:
我无法将父 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) 产生 undefined 并尝试将 topic 记录为“长度应大于 0”产生 [SyntaxError: Unexpected token u]。
我可以这样做吗?如果有,怎么做?
【问题讨论】:
标签: javascript node.js vows