Skip to content

Instantly share code, notes, and snippets.

@Unitech
Created May 21, 2014 12:13
Show Gist options
  • Save Unitech/c3da3213cba87f362fde to your computer and use it in GitHub Desktop.
Save Unitech/c3da3213cba87f362fde to your computer and use it in GitHub Desktop.
Multiple assert
var assert = require('assert');
function Plan(count, done) {
this.done = done;
this.count = count;
}
Plan.prototype.ok = function(expression) {
assert(expression);
if (this.count === 0) {
assert(false, 'Too many assertions called');
} else {
this.count--;
}
if (this.count === 0) {
this.done();
}
};
describe('Asynchronous example', function() {
it('should run two asynchronous methods', function(done) {
var plan = new Plan(2, done);
setTimeout(function() {
plan.ok(true);
}, 50);
setTimeout(function() {
plan.ok(true);
}, 25);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment