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

Fail when passing undefined as the expectation for equals #87

Merged
merged 1 commit into from
Mar 9, 2019

Conversation

mantoni
Copy link
Member

@mantoni mantoni commented Feb 26, 2019

Purpose (TL;DR) - mandatory

This is up for discussion. It's a breaking change and I'm not 100% sure about it.

I noticed that assert.equals(foo.property, bar.property) would pass if both properties are not defined, although it's unlikely that this meets my expectation.

This change throws if the expectation is undefined with a message recommending the use of assert.defined or refute.defined instead.

What are your thoughts on this? If we want to try to protect against cases like these, are there other assertions that should be changed as well?

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. npm t

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

Copy link
Contributor

@mgred mgred left a comment

Choose a reason for hiding this comment

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

LGTM

@mantoni
Copy link
Member Author

mantoni commented Feb 26, 2019

@mgred LGTM is not a discussion 😆 Do you think it's a good idea to introduce this? Are there other cases that come to your mind?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 291

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 286: 0.0%
Covered Lines: 654
Relevant Lines: 654

💛 - Coveralls

@mroderick
Copy link
Member

In my opinion, it is our responsibility as library stewards to guide users away from making mistakes, where we can reasonably detect them. If the author actually want to compare actual with undefined, then the API provides a method to do so.

I think it would be nice if we changed the API a bit, and added isUndefined as an alias of defined. We should deprecate defined, and remove it in the next major version. isUndefined could then be referenced in the error message. Having isUndefined would match the camelCase style of naming the other assertions for special values, like isNull, isTrue, isNaN.

@mantoni
Copy link
Member Author

mantoni commented Feb 27, 2019

I agree with the isUndefined situation. When I started using referee I was intuitively trying this and it didn't work.

@mantoni mantoni added this to the 4.0 milestone Feb 27, 2019
@mantoni mantoni added the semver:major changes will cause a new major version label Feb 27, 2019
@mroderick
Copy link
Member

Let's put this PR and #89 in the same major version.

@mantoni
Copy link
Member Author

mantoni commented Feb 27, 2019

Let's put this PR and #89 in the same major version.

Yep. I already created the 4.0 milestone and added both.

@mgred
Copy link
Contributor

mgred commented Feb 27, 2019

@mgred LGTM is not a discussion 😆 Do you think it's a good idea to introduce this? Are there other cases that come to your mind?

Sorry @mantoni I was a bit fast on this, but still like the idea and think it makes sense in you described scenario 👍

mgred added a commit that referenced this pull request Feb 28, 2019
check if an actual value is undefined

See: #89 #87
mgred added a commit that referenced this pull request Feb 28, 2019
mgred added a commit that referenced this pull request Mar 6, 2019
* feat(isUndefined): add new assetion isUndefined

check if an actual value is undefined

See: #89 #87

* chore: update commons package

to use deprecated wrapper

* deprecate(defined): add warning wrapper
@mantoni mantoni merged commit 41f8748 into master Mar 9, 2019
@mantoni mantoni deleted the equals-undefined branch March 9, 2019 14:35
@mantoni
Copy link
Member Author

mantoni commented Mar 9, 2019

I just saw that isUndefined and the deprecation of refute.defined was already released as v3.2.0. Will send a PR for refute.defined removal to prepare for v4.0.0 then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:major changes will cause a new major version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants