Skip to content

Instantly share code, notes, and snippets.

@bentaber
Created August 17, 2011 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentaber/1152218 to your computer and use it in GitHub Desktop.
Save bentaber/1152218 to your computer and use it in GitHub Desktop.
Vows callbacks drop arguments after error
var vows = require('vows');
var assert = require('assert');
function doSomethingAsync(callback) {
var err = null;
var testValue = 'a';
process.nextTick(function() {
callback(err, testValue);
});
}
function doSomethingAsyncWithError(callback) {
var err = true;
var testValue = 'a';
process.nextTick(function() {
callback(err, testValue);
});
}
vows.describe('simple-async-error').addBatch({
'Generate success response to async function': {
topic: function() {
doSomethingAsync(this.callback)
},
'Validate success': function(err, testValue) {
assert.ok(!err);
},
'Validate testValue': function(err, testValue) {
assert.equal(testValue, 'a');
}
},
'Generate error response to async function': {
topic: function() {
doSomethingAsyncWithError(this.callback)
},
'Validate error': function(err, testValue) {
assert.ok(err);
},
'Validate testValue': function(err, testValue) {
// This assertion fails. It shouldn't.
assert.equal(testValue, 'a');
}
}
}).run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment