From 8f7addce7f5589c0419eba9111f42d8d80ef4411 Mon Sep 17 00:00:00 2001 From: Sylvain Leroux Date: Fri, 5 Jan 2018 20:11:37 +0100 Subject: [PATCH] feat: Add the assert.fail([message]) interface In relation to #1116, the `assert.fail` interface should accept ibeing called with only 1 arguments to fail with a custom message. --- lib/chai/interface/assert.js | 8 ++++++++ test/assert.js | 6 ++++++ 2 files changed, 14 insertions(+) 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);