Skip to content

Commit de12e40

Browse files
feat: add exists alias (#1227)
* feat(assertions): add 'exists' alias (#1225) * docs(assertions): remove bad `exists` example * test(assertions): add `exists` cases * test(should): remove `exists` tests from should interface
1 parent ad385b8 commit de12e40

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/chai/core/assertions.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,19 +824,25 @@ module.exports = function (chai, _) {
824824
*
825825
* expect(null, 'nooo why fail??').to.exist;
826826
*
827+
* The alias `.exists` can be used interchangeably with `.exist`.
828+
*
827829
* @name exist
830+
* @alias exists
828831
* @namespace BDD
829832
* @api public
830833
*/
831834

832-
Assertion.addProperty('exist', function () {
835+
function assertExist () {
833836
var val = flag(this, 'object');
834837
this.assert(
835838
val !== null && val !== undefined
836839
, 'expected #{this} to exist'
837840
, 'expected #{this} to not exist'
838841
);
839-
});
842+
}
843+
844+
Assertion.addProperty('exist', assertExist);
845+
Assertion.addProperty('exists', assertExist);
840846

841847
/**
842848
* ### .empty

test/expect.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ describe('expect', function () {
314314
var foo = 'bar'
315315
, bar;
316316
expect(foo).to.exist;
317+
expect(foo).to.exists;
317318
expect(bar).to.not.exist;
319+
expect(bar).to.not.exists;
318320
expect(0).to.exist;
319321
expect(false).to.exist;
320322
expect('').to.exist;

0 commit comments

Comments
 (0)