Incorrect diff when running asynchronous test in Mocha #270

Closed
paulyoung opened this Issue Jun 11, 2014 · 1 comment

Projects

None yet

2 participants

@paulyoung

I've set truncateThreshold to 0 here to further highlight the issue.

AssertionError: expected { '::window[x]': 0,
  '$header[x]': 0,
  '::window[width]': 385,
  '$header[width]': 385,
  '[header-center-x]': 192.5 } to deeply equal { '::window[x]': 0,
  '::window[width]': 385,
  '$header[x]': 0,
  '$header[width]': 385 }
      + expected - actual

      +{
      +  "$header[width]": 385,
      +  "$header[x]": 0,
      +  "::window[width]": 385,
      +  "::window[x]": 0
      +}
      -{}

The "actual" object is displayed in the diff as an empty object which is not the case. This is shown in the initial error message. Logging error.actual via console.log also shows the object not to be empty.

I'm seeing this when running a test asynchronously using the following format:

it 'should be equal', (done) ->
  try {
    expect(engine.vars).to.deep.equal({
      "::window[x]": 0,
      "::window[width]": windowWidth,
      "$header[x]": 0,
      "$header[width]": windowWidth
    });
    done();
  } catch (error) {
    done(error);
  }

If I make this the only test that runs by using it.only I get the following:

AssertionError: expected { '::window[x]': 0,
  '$header[x]': 0,
  '::window[width]': 385,
  '$header[width]': 385,
  '[header-center-x]': 192.5 } to deeply equal { '::window[x]': 0,
  '::window[width]': 385,
  '$header[x]': 0,
  '$header[width]': 385 }
      + expected - actual

       {
         "$header[width]": 385,
         "$header[x]": 0,
         "::window[width]": 385,
      +  "::window[x]": 0
      -  "::window[x]": 0,
      -  "[header-center-x]": 192.5
       }

This is the expected behavior.

The source code for this test can be found at https://github.com/the-gss/engine/blob/diff-bug/spec/end-to-end.coffee#L1475

@paulyoung paulyoung referenced this issue in gss/engine Jun 11, 2014
Open

Add end-to-end-tests #90

@logicalparadox
Chai.js Assertion Library member

If error.actual and error.expected are being delivered to mocha as you expect (which logging them indicates they are), then this is a problem with mocha's diff display utility. If further research indicates an issue with Chai, please let me know by reopening this issue and pinging me.

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