diff --git a/lib/chai/assertion.js b/lib/chai/assertion.js index 56223a8c6..5830961f4 100644 --- a/lib/chai/assertion.js +++ b/lib/chai/assertion.js @@ -13,6 +13,8 @@ module.exports = function (_chai, util) { var AssertionError = _chai.AssertionError , flag = util.flag; + var count = 0; + /*! * Module export. */ @@ -81,6 +83,14 @@ module.exports = function (_chai, util) { util.overwriteMethod(this.prototype, name, fn); }; + Assertion.getCount = function() { + return count; + }; + + Assertion.resetCount = function() { + count = 0; + }; + /*! * ### .assert(expression, message, negateMessage, expected, actual) * @@ -96,7 +106,10 @@ module.exports = function (_chai, util) { */ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) { + var ok = util.test(this, arguments); + count++; + if (true !== showDiff) showDiff = false; if (true !== Assertion.showDiff) showDiff = false; diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index ce8b9209e..706559298 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -41,6 +41,27 @@ module.exports = function (chai, util) { ); }; + /** + * ### .asserted() + * + * Asserts that assertions have been made. + * + * @name asserted + * @api public + */ + + assert.asserted = function () { + var act = Assertion.getCount(); + var test = new Assertion(null); + + test.assert( + act > 0 + , 'expected one or more assertions' + , '[ negation message unavailable ]' + ); + + }; + /** * ### .fail(actual, expected, [message], [operator]) * diff --git a/test/assert.js b/test/assert.js index b68401674..fa6f38e29 100644 --- a/test/assert.js +++ b/test/assert.js @@ -32,6 +32,17 @@ describe('assert', function () { }, "expected 'test' to be true"); }); + it('asserted', function() { + chai.Assertion.resetCount(); + assert.isTrue(true); + assert.asserted(); + + chai.Assertion.resetCount(); + err(function() { + assert.asserted(); + }, "expected one or more assertions"); + }); + it('ok', function () { assert.ok(true); assert.ok(1);