問(wèn)題描述
我正在使用 Karma 和 Jasmine 進(jìn)行測(cè)試.在某些測(cè)試中,我有測(cè)試所依賴的大對(duì)象.當(dāng)我做類似的事情時(shí)
expect(obj).toEqual(expectedObj);
和 obj != expectedObj
,我在終端中收到一條錯(cuò)誤消息.但是這個(gè)錯(cuò)誤真的很長(zhǎng),因?yàn)樗藘蓚€(gè)對(duì)象,而且很難看出這兩個(gè)對(duì)象在哪些部分不同.
那么,終端有沒有可以與 karma 一起使用的熒光筆?這樣一來(lái),就更容易找出問(wèn)題所在了.
我遇到了同樣的問(wèn)題,對(duì)我來(lái)說(shuō)是
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:
這篇關(guān)于Karma jasmine 測(cè)試:在終端中突出顯示差異的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!