Created
July 27, 2012 15:24
-
-
Save evanp/3188646 to your computer and use it in GitHub Desktop.
Example of using nested teardowns
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'), | |
assert = require('assert'); | |
var suite = vows.describe('test teardown callback'); | |
suite.addBatch({ | |
'when we do an async operation': { | |
topic: function() { | |
var cb = this.callback; | |
process.nextTick(function() { | |
cb(null, 42); | |
}); | |
}, | |
'it works': function(err, value) { | |
assert.ifError(err); | |
assert.equal(value, 42); | |
}, | |
teardown: function(value) { | |
var cb = this.callback; | |
setTimeout(function() { | |
console.log("Second (?) teardown"); | |
cb(null); | |
}, 1000); | |
}, | |
'and we do a sub-context': { | |
topic: function() { | |
var cb = this.callback; | |
process.nextTick(function() { | |
cb(null, 23); | |
}); | |
}, | |
'it works': function(err, value) { | |
assert.ifError(err); | |
assert.equal(value, 23); | |
}, | |
teardown: function(value) { | |
var cb = this.callback; | |
setTimeout(function() { | |
console.log("First (?) teardown"); | |
cb(null); | |
}, 5000); | |
} | |
} | |
} | |
}); | |
suite['export'](module); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment