Created
May 21, 2014 12:13
-
-
Save Unitech/c3da3213cba87f362fde to your computer and use it in GitHub Desktop.
Multiple assert
This file contains hidden or 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 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