mirror of
https://github.com/chaijs/chai
synced 2024-11-14 15:57:10 +00:00
Merge pull request #1117 from s-leroux/assert/fail/only-one-argument
feat: Add the assert.fail([message]) interface
This commit is contained in:
commit
d3908a6688
6 changed files with 96 additions and 12 deletions
|
@ -41,10 +41,18 @@ module.exports = function (chai, util) {
|
|||
};
|
||||
|
||||
/**
|
||||
* ### .fail([message])
|
||||
* ### .fail(actual, expected, [message], [operator])
|
||||
*
|
||||
* Throw a failure. Node.js `assert` module-compatible.
|
||||
*
|
||||
* assert.fail();
|
||||
* assert.fail("custom error message");
|
||||
* assert.fail(1, 2);
|
||||
* assert.fail(1, 2, "custom error message");
|
||||
* assert.fail(1, 2, "custom error message", ">");
|
||||
* assert.fail(1, 2, undefined, ">");
|
||||
*
|
||||
* @name fail
|
||||
* @param {Mixed} actual
|
||||
* @param {Mixed} expected
|
||||
|
@ -55,6 +63,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 = undefined;
|
||||
}
|
||||
|
||||
message = message || 'assert.fail()';
|
||||
throw new chai.AssertionError(message, {
|
||||
actual: actual
|
||||
|
|
|
@ -10,10 +10,18 @@ module.exports = function (chai, util) {
|
|||
};
|
||||
|
||||
/**
|
||||
* ### .fail([message])
|
||||
* ### .fail(actual, expected, [message], [operator])
|
||||
*
|
||||
* Throw a failure.
|
||||
*
|
||||
* expect.fail();
|
||||
* expect.fail("custom error message");
|
||||
* expect.fail(1, 2);
|
||||
* expect.fail(1, 2, "custom error message");
|
||||
* expect.fail(1, 2, "custom error message", ">");
|
||||
* expect.fail(1, 2, undefined, ">");
|
||||
*
|
||||
* @name fail
|
||||
* @param {Mixed} actual
|
||||
* @param {Mixed} expected
|
||||
|
@ -24,6 +32,11 @@ module.exports = function (chai, util) {
|
|||
*/
|
||||
|
||||
chai.expect.fail = function (actual, expected, message, operator) {
|
||||
if (arguments.length < 2) {
|
||||
message = actual;
|
||||
actual = undefined;
|
||||
}
|
||||
|
||||
message = message || 'expect.fail()';
|
||||
throw new chai.AssertionError(message, {
|
||||
actual: actual
|
||||
|
|
|
@ -42,10 +42,19 @@ module.exports = function (chai, util) {
|
|||
var should = {};
|
||||
|
||||
/**
|
||||
* ### .fail([message])
|
||||
* ### .fail(actual, expected, [message], [operator])
|
||||
*
|
||||
* Throw a failure.
|
||||
*
|
||||
* should.fail();
|
||||
* should.fail("custom error message");
|
||||
* should.fail(1, 2);
|
||||
* should.fail(1, 2, "custom error message");
|
||||
* should.fail(1, 2, "custom error message", ">");
|
||||
* should.fail(1, 2, undefined, ">");
|
||||
*
|
||||
*
|
||||
* @name fail
|
||||
* @param {Mixed} actual
|
||||
* @param {Mixed} expected
|
||||
|
@ -56,6 +65,11 @@ module.exports = function (chai, util) {
|
|||
*/
|
||||
|
||||
should.fail = function (actual, expected, message, operator) {
|
||||
if (arguments.length < 2) {
|
||||
message = actual;
|
||||
actual = undefined;
|
||||
}
|
||||
|
||||
message = message || 'should.fail()';
|
||||
throw new chai.AssertionError(message, {
|
||||
actual: actual
|
||||
|
|
|
@ -14,10 +14,24 @@ describe('assert', function () {
|
|||
}, "expected foo to equal `bar`");
|
||||
});
|
||||
|
||||
it('fail', function () {
|
||||
chai.expect(function () {
|
||||
assert.fail(0, 1, 'this has failed');
|
||||
}).to.throw(chai.AssertionError, /this has failed/);
|
||||
describe("fail", function() {
|
||||
it('should accept a message as the 3rd argument', function () {
|
||||
err(function() {
|
||||
assert.fail(0, 1, 'this has failed');
|
||||
}, /this has failed/);
|
||||
});
|
||||
|
||||
it('should accept a message as the only argument', function () {
|
||||
err(function() {
|
||||
assert.fail('this has failed');
|
||||
}, /this has failed/);
|
||||
});
|
||||
|
||||
it('should produce a default message when called without any arguments', function () {
|
||||
err(function() {
|
||||
assert.fail();
|
||||
}, /assert\.fail()/);
|
||||
});
|
||||
});
|
||||
|
||||
it('isTrue', function () {
|
||||
|
|
|
@ -236,10 +236,24 @@ describe('expect', function () {
|
|||
, 'of', 'same', 'but', 'does' ].forEach(test);
|
||||
});
|
||||
|
||||
it('fail', function () {
|
||||
err(function() {
|
||||
expect.fail(0, 1, 'this has failed');
|
||||
}, /this has failed/);
|
||||
describe("fail", function() {
|
||||
it('should accept a message as the 3rd argument', function () {
|
||||
err(function() {
|
||||
expect.fail(0, 1, 'this has failed');
|
||||
}, /this has failed/);
|
||||
});
|
||||
|
||||
it('should accept a message as the only argument', function () {
|
||||
err(function() {
|
||||
expect.fail('this has failed');
|
||||
}, /this has failed/);
|
||||
});
|
||||
|
||||
it('should produce a default message when called without any arguments', function () {
|
||||
err(function() {
|
||||
expect.fail();
|
||||
}, /expect\.fail()/);
|
||||
});
|
||||
});
|
||||
|
||||
it('true', function(){
|
||||
|
|
|
@ -233,10 +233,24 @@ describe('should', function() {
|
|||
, 'of', 'same', 'but', 'does' ].forEach(test);
|
||||
});
|
||||
|
||||
it('fail', function () {
|
||||
err(function() {
|
||||
should.fail(0, 1, 'this has failed');
|
||||
}, 'this has failed');
|
||||
describe("fail", function() {
|
||||
it('should accept a message as the 3rd argument', function () {
|
||||
err(function() {
|
||||
should.fail(0, 1, 'this has failed');
|
||||
}, /this has failed/);
|
||||
});
|
||||
|
||||
it('should accept a message as the only argument', function () {
|
||||
err(function() {
|
||||
should.fail('this has failed');
|
||||
}, /this has failed/);
|
||||
});
|
||||
|
||||
it('should produce a default message when called without any arguments', function () {
|
||||
err(function() {
|
||||
should.fail();
|
||||
}, /should\.fail()/);
|
||||
});
|
||||
});
|
||||
|
||||
it('root exist', function () {
|
||||
|
|
Loading…
Reference in a new issue