diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 7772e2c4b..387f3856a 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -41,6 +41,7 @@ module.exports = function (chai, util) { }; /** + * ### .fail([message]) * ### .fail(actual, expected, [message], [operator]) * * Throw a failure. Node.js `assert` module-compatible. @@ -55,6 +56,13 @@ module.exports = function (chai, util) { */ assert.fail = function (actual, expected, message, operator) { + if (arguments.length < 2) { + // Comply with Node's fail([message]) interface + + message = actual; + actual = expected = undefined; + } + message = message || 'assert.fail()'; throw new chai.AssertionError(message, { actual: actual diff --git a/test/assert.js b/test/assert.js index d23cb3709..d213e5735 100644 --- a/test/assert.js +++ b/test/assert.js @@ -20,6 +20,12 @@ describe('assert', function () { }).to.throw(chai.AssertionError, /this has failed/); }); + it('fail', function () { + chai.expect(function () { + assert.fail('this has failed'); + }).to.throw(chai.AssertionError, /this has failed/); + }); + it('isTrue', function () { assert.isTrue(true);