Skip to content

Instantly share code, notes, and snippets.

@evanp
Created July 27, 2012 15:24
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 evanp/3188646 to your computer and use it in GitHub Desktop.
Save evanp/3188646 to your computer and use it in GitHub Desktop.
Example of using nested teardowns
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