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

No mismatch highlighted on -0 !== 0 deep equality mismatch #572

Closed
rreusser opened this issue Apr 30, 2016 · 0 comments
Assignees
Labels
bug
Milestone

Comments

@rreusser
Copy link

@rreusser rreusser commented Apr 30, 2016

Version: 10.3.2

Expected behavior: The reporter highlights all deep equality mismatches that caused the assertion to fail, allowing the user to determine the cause.

Observed behavior: Hoek returns false when comparing 0 to -0, but the reporter uses string comparison that converts -0 to "0", resulting in a failed assertion with no highlighted output. (side note: I didn't expect Hoek to be this strict since, generally speaking in JS, 0 === -0)

Steps to reproduce: (See full gist here: zero-test.js)

describe('negative zero check', function () {
  it('highlights mismatch when deep equality fails', function (done) {
    expect([0]).to.deep.equal([-0]);
    done();
  }); 
});

I get the output:

Failed tests:
  1) negative zero check highlights mismatch when deep equality fails:
      actual expected
      [
        0
      ]
      Expected [ 0 ] to equal specified value
      at /Users/rreusser/projects/node/zerotest/index.js:10:25

Of course there's no coloring here, but there's no indication of why the test failed—which turns out to take a bit of time and sanity-check exhaustion to determine in a nontrivial case.

It seems like reliance on StringifySafe is the source of the problem since -0 is stringified as "0" instead of "-0" so that a string diff returns nothing. Unfortunately, I can't think of a great solution here since StringifySafe otherwise does exactly what it needs to do and saves a lot of recursion and complexity—and is probably correct to convert -0 to "0". This could all be obscure enough to not be a big deal, but I'm glad to hear or offer thoughts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.