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

add exists alias #1227

merged 4 commits into from
Feb 4, 2021

Conversation

blake-regalia
Copy link
Contributor

Closes #1225 .

@blake-regalia blake-regalia requested a review from a team as a code owner January 16, 2019 16:54
@codecov
Copy link

codecov bot commented Jan 16, 2019

Codecov Report

Merging #1227 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1227      +/-   ##
==========================================
+ Coverage   94.51%   94.51%   +<.01%     
==========================================
  Files          32       32              
  Lines        1676     1678       +2     
  Branches      404      404              
==========================================
+ Hits         1584     1586       +2     
  Misses         92       92
Impacted Files Coverage Δ
lib/chai/core/assertions.js 99.39% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1cededa...9124de7. Read the comment docs.

Copy link
Contributor

@meeber meeber left a comment

Choose a reason for hiding this comment

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

@blake-regalia Thanks for submitting this. Let's add a couple of tests to the expect and should interfaces. Duplicates of these two and these two using exists instead of exist should suffice. It's okay if the grammar is wrong.

@@ -814,23 +814,32 @@ module.exports = function (chai, _) {
* expect(undefined).to.be.undefined; // Recommended
* expect(undefined).to.not.exist; // Not recommended
*
* Use after `.property` to assert that a value is not `null` nor `undefined`.
* expect({a: 1}}).to.have.property('a').that.exists;
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 not sure I like this example. For the most part, we discourage the use of .exists in favor of a precise assertion whenever reasonable. For example:

expect({a: 1}).to.have.property('a', 1); // Recommended
expect({a: 1}).to.have.property('a').that.equals(1); // Recommended
expect({a: 1}).to.have.property('a').that.exists; // Not recommended

Copy link
Contributor Author

@blake-regalia blake-regalia Jan 19, 2019

Choose a reason for hiding this comment

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

Agreed. I'll remove this part. In fact the use case that motivated this PR is for an interface test suite that requires an implementation to have some property that is set to some value which is not null nor undefined, a less common situation where the actual value (as well as the type) of the property is not known/important.

test/should.js Outdated
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.

@vieiralucas
Copy link
Member

This PR looks good, but I'm not sure if we should merge this since we will start merging new-chai into this repo.
Should we wait for after new-chai is here to add this assertion? Will chai 5 even have an exists assertion?

@keithamus ?

@lucasfcosta
Copy link
Member

@vieiralucas I'm happy to get this merged in as it's an improvement to the current codebase that has 0 cost.
IMO our approach to v4 is to get contributions and improvements that don't add any overhead or do critical fixes but avoid putting too much effort into it as we move towards v5 since that's our main goal atm.

@vieiralucas
Copy link
Member

Yes, I got it wrong about new-chai
But I believe we should merge #1249 before merging this since it should be easier to fix conflicts.

Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

Excellent, let's get this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expect(...).to.have.property(...).that.exists
6 participants