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
Merged

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

merged 1 commit into from
Sep 29, 2014

Conversation

mohayonao
Copy link
Contributor

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

👍 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

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
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.

None yet

3 participants