我对node.js测试完全陌生,也许你可以帮助我:我想用誓言和tobi为我的express webapp做一些或多或少的简单测试(例如,测试登录路由是否工作)。
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)我不能从这个输出中识别出哪里出了问题,但我猜这与回调有关。我对node.js中的异步编程风格也相当陌生。
发布于 2012-01-10 15:03:39
vows期望回调的第一个参数是错误的。如果它不是空的或未定义的,它就会认为有问题。您必须将回调封装到一个匿名函数中,该函数以null作为第一个参数来调用它。
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);https://stackoverflow.com/questions/8796666
复制相似问题