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

fix: closeTo should check value's type before assertion #279

Merged
merged 1 commit into from Sep 29, 2014

Conversation

@mohayonao
Copy link
Contributor

@mohayonao mohayonao commented Jul 13, 2014

Assertion#closeTo passes tests that should be failed.

e.g.

expect([1.5]).to.be.closeTo(1.0, 0.5); // PASS???
expect(1.5).to.be.closeTo("1.0", 0.5); // PASS???

so, I fixed it.

expect([1.5]).to.be.closeTo(1.0, 0.5); // throw "expected [ 1.5 ] to be a number"
expect(1.5).to.be.closeTo("1.0", 0.5); // throw "expected '1.0' to be a number"
@charlierudolph
Copy link
Contributor

@charlierudolph charlierudolph commented Jul 15, 2014

👍 Definitely a useful error message.

I think the message should be different though when the supplied arguments to closeTo are wrong versus the actual value. Should probably verify delta is a number too.

expect([1.5]).to.be.closeTo(1.0, 0.5); // throw "expected [ 1.5 ] to be a number"
expect(1.5).to.be.closeTo("1.0", 0.5); // throw "the arguments to closeTo must be numbers"
expect(1.5).to.be.closeTo(1.0, "0.5"); // throw "the arguments to closeTo must be numbers"
@mohayonao
Copy link
Contributor Author

@mohayonao mohayonao commented Jul 16, 2014

I agree.
I've fixed this commit to throw understandable error messages.
Thanks!

expect([1.5]).to.be.closeTo(1.0, 0.5); // throw "expected [ 1.5 ] to be a number"
expect(1.5).to.be.closeTo("1.0", 0.5); // throw "the arguments to closeTo must be numbers"
expect(1.5).to.be.closeTo(1.0, "0.5"); // throw "the arguments to closeTo must be numbers"
logicalparadox added a commit that referenced this pull request Sep 29, 2014
fix: closeTo should check value's type before assertion
@logicalparadox logicalparadox merged commit 3e692e6 into chaijs:master Sep 29, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.