added check for logging negative zero #298

Merged
merged 4 commits into from Nov 3, 2014

Projects

None yet

4 participants

@dasilvacontin
Contributor

As @Lexicality mentions in issue #223, when asserting 0 against -0, Chai throws AssertionError: expected 0 to deeply equal 0 without any further information.

With the check in this PR, Chai throws AssertionError: expected 0 to deeply equal -0.

@keithamus keithamus and 1 other commented on an outdated diff Oct 31, 2014
lib/chai/utils/inspect.js
@@ -191,6 +191,9 @@ function formatPrimitive(ctx, value) {
return ctx.stylize(simple, 'string');
case 'number':
+ if (value === 0 && Infinity !== (1 / value)) {
@keithamus
keithamus Oct 31, 2014 Member

Nice work @dasilvacontin but there is some serious reverse logic going on here. Surely this would be better written as value === 0 && (1/value) === -Infinity?

@dasilvacontin
dasilvacontin Oct 31, 2014 Contributor

I totally agree with that! Thanks for pointing it out, @keithamus ! 😄

@keithamus
Member

LGTM. @logicalparadox am I good to merge?

@logicalparadox
Member

Missing test asserting this works.

@Lexicality

👍

@dasilvacontin
Contributor

Added some assertions. If it needs any other change, suggestions are welcome.

@logicalparadox
Member

👍

@keithamus keithamus merged commit 3e35adf into chaijs:master Nov 3, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@keithamus
Member

Sorry @logicalparadox about missing the test - I'll ensure to be extra vigilant next time!

@dasilvacontin
Contributor

Sorry for missing it too! :/

@dasilvacontin dasilvacontin deleted the dasilvacontin:negativeZeroLogging branch Nov 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment