Reputation: 950
I'm completely new to node.js testing, maybe you can help me out: I want to do some more or less simple tests for my express webapp using vows and tobi (for example testing if the login route works)
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);
and I get this:
♢ 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)
I can't recognize what's wrong from this output but I'm guessing it has someone to do with callbacks. I'm also fairly new to the async style of programming in node.js.
Upvotes: 1
Views: 416
Reputation: 18217
vows expects the first argument to the callback to be an error. If it's not null or undefined it thinks something's wrong. You'll have to wrap the callback into an anonymous function that calls it with null as its first argument.
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);
Upvotes: 1