diff --git a/lib/chai/interface/expect.js b/lib/chai/interface/expect.js index b827df7da..89f9efd52 100644 --- a/lib/chai/interface/expect.js +++ b/lib/chai/interface/expect.js @@ -8,5 +8,26 @@ module.exports = function (chai, util) { chai.expect = function (val, message) { return new chai.Assertion(val, message); }; -}; + /** + * ### .fail(actual, expected, [message], [operator]) + * + * Throw a failure. + * + * @name fail + * @param {Mixed} actual + * @param {Mixed} expected + * @param {String} message + * @param {String} operator + * @api public + */ + + chai.expect.fail = function (actual, expected, message, operator) { + message = message || 'expect.fail()'; + throw new chai.AssertionError(message, { + actual: actual + , expected: expected + , operator: operator + }, chai.expect.fail); + }; +}; diff --git a/lib/chai/interface/should.js b/lib/chai/interface/should.js index ddf4495b0..2b38f9a54 100644 --- a/lib/chai/interface/should.js +++ b/lib/chai/interface/should.js @@ -40,6 +40,28 @@ module.exports = function (chai, util) { var should = {}; + /** + * ### .fail(actual, expected, [message], [operator]) + * + * Throw a failure. + * + * @name fail + * @param {Mixed} actual + * @param {Mixed} expected + * @param {String} message + * @param {String} operator + * @api public + */ + + should.fail = function (actual, expected, message, operator) { + message = message || 'should.fail()'; + throw new chai.AssertionError(message, { + actual: actual + , expected: expected + , operator: operator + }, should.fail); + }; + should.equal = function (val1, val2, msg) { new Assertion(val1, msg).to.equal(val2); }; diff --git a/test/expect.js b/test/expect.js index e1e2f4d8f..9db12dee0 100644 --- a/test/expect.js +++ b/test/expect.js @@ -10,6 +10,12 @@ describe('expect', function () { expect('foo').to.equal('foo'); }); + it('fail', function () { + err(function() { + expect.fail(0, 1, 'this has failed'); + }, /this has failed/); + }); + it('true', function(){ expect(true).to.be.true; expect(false).to.not.be.true; diff --git a/test/should.js b/test/should.js index 7d96f828b..4c18e03b0 100644 --- a/test/should.js +++ b/test/should.js @@ -7,6 +7,12 @@ describe('should', function() { should.not.equal('foo', 'bar'); }); + it('fail', function () { + err(function() { + should.fail(0, 1, 'this has failed'); + }, 'this has failed'); + }); + it('root exist', function () { var foo = 'foo' , bar = undefined;