chai: Make error message more descriptive

Sometimes error messages for hash comparison looks like that

expect(data.pagination).to.eql
  currentPage      : 2
  perPage          : 3
  pagesCount       : 3
  currentPagePath  : '/tag/News?page=2'
  firstPagePath    : '/tag/News'
  previousPagePath : '/tag/News'
  nextPagePath     : '/tag/News?page=3'
  lastPagePath     : '/tag/News?page=3'
expected { Object (currentPage, perPage, ...) } to deeply equal { Object (currentPage, perPage, ...) }

looking at such message it’s hard to understand what’s wrong there.

Maybe add more details?

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 20 (9 by maintainers)

Commits related to this issue

Most upvoted comments

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
}