Assertion Error Diffs with Karma, Mocha, and Chai

Karma Mocha Show Diff

I’ve been frustrated the lack of diffs in Karma with Mocha and Chai as the test and assertion backends.

Turns out support for better diffs has been around for years. It just requires that a configuration option be set.

// in karma.conf.js
module.exports = function (cfg) {
        // ...

        // this is it! Better diffs built in!
        mochaReporter: {
            showDiff: true,

The result is wonderful diffs that show’s exactly what’s missing or different.

Karma Mocha Show Diff