I'm trying to start my node.js project with BDD using vows.
Then I got this strange error.
I was trying to write a small route testing for express with vows and here is my original code,
node_server.prototype.mainpage = function(callback) {
http.get({host:'localhost', port:this.port, path:'/', agent:false}, function(res){
callback(res.statusCode);
});
}
And here is how I write my vows testing
vows.describe('Request to the server').addBatch({
'Should get http 200': {
topic: function () {
app_server.mainpage(this.callback)
},
'we get 200': function (statusCode) {
app_server.close_server();
assert.equal(statusCode, 200);
}
},
}).run(); // Run it
Vows always report an unexpected error even though the statusCode is correct, like this
» An unexpected error was caught: 200
So I change my mainpage function like this
node_server.prototype.mainpage = function(callback) {
http.get({host:'localhost', port:this.port, path:'/', agent:false}, function(res){
callback("error", res.statusCode); // Here I added a err message in front of the status code.
});
}
And I also change my test suite as
'we get 200': function (err, statusCode) {
Then this testing worked!
I'm just wondering how could this strange situation happened. I've read the documentation of vows but I didn't find anywhere they said I must put 2 parameters to a cb instead of 1.
Give me some clues!
Thank you in advance!