nodejs deep equal with differences

Is there a assertion library that will show me what are the differences between two objects when compared deeply ?

I've tried using chai but it just tells me that the objects are different but not where. Same thing for node's assert....

Substack's difflet is probably what you need

Update: but wait, there is more: https://github.com/andreyvit/json-diff https://github.com/algesten/jsondiff https://github.com/samsonjs/json-diff

Using chai 1.5.0 and mocha 1.8.1, the following works for me:

var expect = require('chai').expect;

it("shows a diff of arrays", function() {
  expect([1,2,3]).to.deep.equal([1,2,3, {}]);
});

it("shows a diff of objects", function() {
  expect({foo: "bar"}).to.deep.equal({foo: "bar", baz: "bub"});
});

results in:

✖ 2 of 2 tests failed:

1)  shows a diff of arrays:

  actual expected

  1 | [
  2 |   1,
  3 |   2,
  4 |   3,
  5 |   {}
  6 | ]

2)  shows a diff of objects:

  actual expected

  {
    "foo": "bar",
    "baz": "bub"
  }

What does not show here is that the output is highlighted red/green where lines are unexpected/missing.

Based on this StackOverflow answer, I believe the issue was occuring for me because my tests were asynchronous.

I got diffs working correctly again by using the following pattern:

try {
  expect(true).to.equal(false);
  done();  // success: call done with no parameter to indicate that it() is done()
} catch(e) {
  done(e);  // failure: call done with an error Object to indicate that it() failed
}