Tuesday, 15 July 2014

javascript - Asynchronous Topic Scope Vows.JS -



javascript - Asynchronous Topic Scope Vows.JS -

i'm having problem passing parent topic values children topic values. code asynchronous , think i'm having problem. want part of json response topic of tests underneath. here relevant parts of tests.

{ "a test":{ topic: function() { request(conf.server + '/categories/' + id, this.callback) }, 'should respond 200': function(err, res, body) { res.statuscode.should.equal(200); console.log(json.parse(body).title); }, 'should have valid json in body': function(err, res, body) { (function() { json.parse(body); }).should.not. throw(); }, 'category collection': { topic: function(err, res, body) { console.log(res.statuscode); homecoming json.parse(body).categories }, 'should have length greater 0': function(topic) { topic.length.should.be.above(0); } } } }

console.log(res.statuscode) yields undefined , trying log topic in "should have length greater 0" yields [syntaxerror: unexpected token u].

can this? if so, how?

i did quick test on this, seems when first parameter i.e. err null, not passed sub-context. other parameters passed. here code.:

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 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 null' : function(err, firstchild) { assert.isnull(err); assert.isnotnull(firstchild); } } } }); suite.run(); }());

result err: first, first: second, second: undefined ✓ ok » 2 honored.

but when pass in error, log not printed , sub-context errors.

i don't know exact reasons of this.i check vows code , if find anything. hope useful you.

javascript node.js vows

No comments:

Post a Comment