I'm having trouble passing parent topic values to children topic values. The code is asynchronous and I think that is where I'm having the problem. I want a part of the JSON response to be the topic of the tests underneath. Here is the relevant parts of the tests.
{
"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) yields undefined and trying to log the topic in "should have a length greater than 0" yields [SyntaxError: Unexpected token u].
Can I do this? If so, how?
I did a quick test on this, it seems that when first parameter i.e. err is null, it is not passed to sub-context. All other parameters are passed. Here is my code.:
Result was
Err: first, first: second, second: undefined ✓ OK » 2 honored.But when I pass something in error, log is not even printed and sub-context errors.
I don't know exact reasons of this.I will check vows code and get back if I find anything. Hope this is somewhat useful to you.