Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upChai's deepEqual does not show an object diff when run in mocha with Karma #76
Comments
|
I don't think this issue is directly with karma-mocha, but rather with mocha |
|
@dignifiedquire I don't believe thats the case, as when you run the tests directly in mocha in a node.js environment, without karma, via the cli with:
You get the desired detailed diff output |
|
@oveddan how look mocha result if you run mocha in browser? In reality Thanks |
|
@maksimr Same issue: |
|
@dignifiedquire You are right - it has to do with the actual mocha test runners. I ran these tests with Karma in the chrome environment as @maksimr suggested using the chrome debugger, and discovered: Looking at the chai.js code, it throws an Mocha's html runner does not look at the actual/expected values coming from chai's This issue belongs in Mocha :) |
|
If you use karma-mocha-reporter, there is a "showDiff" configuration option:
|
|
@ItsCosmo wow, it's so much better with that option set. Thanks! I wonder why that isn't the default. |

When using mocha and chai in a Node.js environment, when an assertion using deepEquals fails, you get a detailed output showing piece by piece what is different between the expected and actual values.
Take for example, these tests, located in a file,
tests/objects_are_equal.js:If you run the above tests with mocha in a node.js environment, with the command

mocha, you get the following output:But if you run them using karma-mocha, you get the following output:

This makes it really challenging to debug why object comparisons didn't work, and I find myself having to do console.log on the objects in the test to see what is different between objects, which is not ideal.
According to an issue in chai:
I'm not sure if this bug belongs in karma-mocha or karma.
The bug still happens if the tests run in Chrome or Phantomjs, and if I load chai.js directly onto the page instead of via a karma-chai.
For the reference, here is my karma.conf file: