Skip to content

Commit

Permalink
feat: add exists alias (#1227)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
blake-regalia authored Feb 4, 2021
1 parent ad385b8 commit de12e40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de12e40

Please sign in to comment.