mocha icon indicating copy to clipboard operation
mocha copied to clipboard

Assertions that compare two numbers for equality are confusing

Open callumlocke opened this issue 8 years ago • 5 comments

Maybe it's just me, but I find this presentation very confusing:

image

It takes me a few seconds to mentally parse that. The plus and minus characters throw me because they look like they're positive/negative numbers at first. (I get that it's standard diff formatting, but I don't think diff formatting is appropriate when comparing integers.) After that, you have to mentally link up the colours or the symbols to work out which way round the problem is.

Wouldn't something like this be much clearer:

      AssertionError: should contain one changed file

        expected: 1
          actual: 2

(This could be just for when both the expected and actual values are numbers.)

callumlocke avatar Dec 14 '15 10:12 callumlocke

+1 for better message. I too find it confusing +/- with numbers the expected: actual: is much clearer.

bcowgill avatar Dec 16 '15 15:12 bcowgill

+1

smartmouse avatar Jan 09 '16 05:01 smartmouse

+1 this has always sucked, good call

ORESoftware avatar Feb 07 '16 07:02 ORESoftware

This will be a step in the right direction, but the tricky bit will be to filter out true strings and/or numbers from garbled stringified objects, like this one:

"[\n    first-array-entry\n    second-array-entry\n]"

kunagpal avatar May 25 '17 21:05 kunagpal

I find both the order and colors confusing here. For a diff the convention is

-before
+after

so seeing as expected is the "before" state and actual is the "after" state, mocha's diff is backwards. Instead of

-actual
+expected

it should be

-expected
+actual

MetRonnie avatar Aug 26 '22 12:08 MetRonnie