diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index d998c9200..71baf3a99 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -824,19 +824,25 @@ module.exports = function (chai, _) { * * expect(null, 'nooo why fail??').to.exist; * + * The alias `.exists` can be used interchangeably with `.exist`. + * * @name exist + * @alias exists * @namespace BDD * @api public */ - Assertion.addProperty('exist', function () { + function assertExist () { var val = flag(this, 'object'); this.assert( val !== null && val !== undefined , 'expected #{this} to exist' , 'expected #{this} to not exist' ); - }); + } + + Assertion.addProperty('exist', assertExist); + Assertion.addProperty('exists', assertExist); /** * ### .empty diff --git a/test/expect.js b/test/expect.js index 88a6133cf..78ab661bf 100644 --- a/test/expect.js +++ b/test/expect.js @@ -314,7 +314,9 @@ describe('expect', function () { var foo = 'bar' , bar; expect(foo).to.exist; + expect(foo).to.exists; expect(bar).to.not.exist; + expect(bar).to.not.exists; expect(0).to.exist; expect(false).to.exist; expect('').to.exist;