Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2011 01:41
Show Gist options
  • Save anonymous/1182624 to your computer and use it in GitHub Desktop.
Save anonymous/1182624 to your computer and use it in GitHub Desktop.
Vows asynchronous test confused my poor brain
var vows = require('vows');
var assert = require('assert');
var vowSuite = vows.describe('Vows');
vowSuite.addBatch({
'Call callback with error and one extra parameter':{
topic: function(){
var callback = this.callback;
setTimeout(function(){
callback(null, [4,5,6]);
}, 100);
},
'I DO NOT put error in my parameter list': function(array){
console.log('Array 1', array);
assert.equal(array.length, 3);
},
'I DO put error in my parameter list': function(error, array){
console.log('Error 2', error);
console.log('Array 2', array);
assert.equal(array.length, 3);
}
},
'Call callback with error and two extra parameters':{
topic: function(){
var callback = this.callback;
setTimeout(function(){
callback(null, [4,5,6], 42);
}, 100);
},
'I DO NOT put error in my parameter list': function(array, number){
console.log('Array 3', array);
console.log('Number 3', number);
assert.equal(array.length, 3);
assert.equal(number, 42);
},
'I DO put error in my parameter list': function(error, array, number){
console.log('Error 4', error);
console.log('Array 4', array);
console.log('Number 4', number);
assert.equal(array.length, 3);
assert.equal(number, 42);
}
}
});
vowSuite.export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment