Created
August 17, 2011 18:17
-
-
Save bentaber/1152218 to your computer and use it in GitHub Desktop.
Vows callbacks drop arguments after error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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