Change toBeCloseTo matcher to be more consistent #264

Merged
merged 1 commit into from Aug 12, 2012

Projects

None yet

2 participants

@dburt

It now calculates and compares a difference, rather than rounding
two separate quantities and testing for their equality.

This fixes the problem where:
expect(1.225).toBeCloseTo(1.234); // difference is 0.009, and it passes
expect(1.225).toBeCloseTo(1.224); // difference is 0.001, but it fails

All the existing specs still pass; I've just added two examples like the above, with the first negated.

@dburt dburt Change toBeCloseTo matcher to be more consistent.
It now calculates and compares a difference, rather than rounding
two separate quantities and testing for their equality.
7e04571
@infews infews merged commit 06c900a into jasmine:master Aug 12, 2012
@infews

Thanks for finding this. And thanks for using Jasmine!

@dburt

Thanks for writing it, and for merging my change! It caused me a bit of grief.

(I think an even better version would have an absolute (rather than logarithmic) second argument, like RSpec's version, like this: expect(1.23).toBeCloseTo(1.234, 0.1) -- but that would probably not be backwards-compatible -- although you could use that rule only for fractional arguments...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment