用Vows和Tobi进行Webapptesting

我完全是新的node.jstesting,也许你可以帮助我:我想要做一些或多或less简单的testing我的快速webapp使用誓言和tobi(例如testing如果login路线的作品)

var vows = require('vows'); var assert = require('assert'); var tobi = require('tobi'); var browser = tobi.createBrowser(8080, 'localhost'); vows.describe('mytest').addBatch({ 'GET /': { topic: function() { browser.get("/", this.callback); }, 'has the right title': function(res, $) { $('title').should.equal('MyTitle'); } } }).export(module); 

我得到这个:

 ♢ mytest GET / ✗ has the right title » expected { '0': { _ownerDocument: [....lots of stuff, won't paste it all.....] Entity: [Function: Entity], EntityReference: [Function: EntityReference] } }, selector: ' title' } to equal 'MyTitle' // should.js:295 ✗ Broken » 1 broken (0.126s) 

我不知道这个输出有什么问题,但是我猜测它有一个与callback有关的问题。 我也是node.js中asynchronous编程风格的新手。

誓言期望callback的第一个参数是一个错误。 如果它不是null或undefined,它认为是错的。 你必须把callback包装成一个匿名函数,用它作为第一个参数来调用它。

 vows.describe('mytest').addBatch({ 'GET /': { topic: function() { var cb = this.callback; browser.get("/", function() { var args = Array.prototype.slice.call(arguments); cb.apply(null, [null].concat(args)); }); }, 'has the right title': function(err, res, $) { $('title').should.equal('MyTitle'); } } }).export(module);