Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exists alias #1227

Merged
merged 4 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,19 +818,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
2 changes: 2 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ describe('should', function() {
var foo = 'foo'
, bar = undefined;
should.exist(foo);
should.exists(foo);
should.not.exist(bar);
should.not.exists(bar);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, it looks like I gave bad guidance here. I see now that the exist assertion is exposed in a different way for the should interface. I don't think there's any need to add a plural version for the should interface, so we can remove these tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blake-regalia Do you have a few min to remove these .should tests? Apologies for the inconvenience.

Copy link
Contributor Author

@blake-regalia blake-regalia Feb 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem @meeber ! Thanks for following up with this.

should.exist(0);
should.exist(false);
should.exist('');
Expand Down