Karma茉莉花测试:在终端突出显示差异 [英] Karma jasmine tests: Highlight diff in terminal

查看:98
本文介绍了Karma茉莉花测试:在终端突出显示差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Karma和Jasmine进行测试。在某些测试中,我有大量的测试依赖的对象。当我做类似的事情时

  expect(obj).toEqual(expectedObj); 

obj!= expectedObj ,我得到了我的终端中的错误消息。 但是这个错误确实很长,因为它包含了两个对象,而且很难看出这两个对象在哪些部分是不同的。



那么,是否有终端的荧光笔,可以与业力一起使用?通过这种方式,可以更容易找出错误。

解决方案

我遇到了同样的问题,它做了什么对我来说是


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.

解决方案

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:

这篇关于Karma茉莉花测试:在终端突出显示差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆