Count assertions in your test cases with static code analysis before execution and wait until all assertions are completed.
Input:
var esplan = require('esplan');
var assert = esplan.register(require('assert'));
describe('Promise', function() {
it('can not detect an assertion error in `then` function', function() {
mayBeResolve().then(function(value) {
assert.equal(value.length, 2);
assert.equal(value[0], 'foo');
assert.equal(value[1], 'bar');
});
});
});
Output:
var esplan = require('esplan');
var assert = esplan.register(require('assert'));
describe('Promise', function () {
// `$$done` is added!
it('can not detect an assertion error in `then` function', function($$done) {
assert.$$plan(this, 3, $$done); // this line is inserted!
mayBeResolve().then(function (value) {
assert.equal(value.length, 2);
assert.equal(value[0], 'foo');
assert.equal(value[1], 'bar');
});
});
});
Result (If mayBeResolve()
returns wrong value ['foo', 'wrong!']
):
Error: Expected 3 assertions, but actually 2 assertions called
MIT License: Teppei Sato <[email protected]>