9

I'm using Karma with Jasmine for my tests. In some tests, I have large objects that the test relies on. When I do something like

expect(obj).toEqual(expectedObj);

and obj != expectedObj, I get an error message in my terminal. But this error is really long, because it includes both of the objects, and it's very hard to see, in what parts the two objects are different.

So, is there any highlighter for the terminal, that can be used along with karma? This way, it would be much more easy to figure out, what's wrong.

23tux
  • 14,104
  • 15
  • 88
  • 187
  • Unfortunately, I haven't found any plugins for highlighting the code diff in terminal. Or does anyone have a guide, how to write such a thing by myself? – 23tux May 23 '14 at 09:46
  • 1
    For info, there is a duplicate [here](http://stackoverflow.com/questions/24076429/karma-jasmine-console-more-detailed-test-results) and an opened [issue](https://github.com/karma-runner/karma/issues/627) on Karma GitHub. – glepretre Jun 11 '14 at 08:52

1 Answers1

8

I had the same problem and what did it for me was karma-jasmine-diff-reporter.

Just install it:

npm install karma-jasmine-diff-reporter --save-dev

and configure it as a reporter, eg:

// karma.conf.js 
module.exports = function(config) {
  config.set({     

    reporters: ['jasmine-diff']     

  });
};

You can configure it to pretty print:

    // karma.conf.js 
    module.exports = function(config) {
      config.set({     

        reporters: ['jasmine-diff'],     

        jasmineDiffReporter: {
            pretty: true, // 2 spaces by default for one indent level
            matchers: {
                toEqual: {
                    pretty: false   // disable pretty print for toEqual
                }
            }
        }         
      });
    };

Output will be something like this:

Output example

Rui Marques
  • 8,567
  • 3
  • 60
  • 91