Skip to content

Commit

Permalink
feat: Add the assert.fail([message]) interface
Browse files Browse the repository at this point in the history
In relation to chaijs#1116, the `assert.fail` interface should accept
ibeing called with only 1 arguments to fail with a custom message.
  • Loading branch information
s-leroux committed Jan 5, 2018
1 parent f54f71c commit 8f7addc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/chai/interface/assert.js
Expand Up @@ -41,6 +41,7 @@ module.exports = function (chai, util) {
};

/**
* ### .fail([message])
* ### .fail(actual, expected, [message], [operator])
*
* Throw a failure. Node.js `assert` module-compatible.
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/assert.js
Expand Up @@ -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);

Expand Down

0 comments on commit 8f7addc

Please sign in to comment.