【发布时间】:2014-05-15 11:06:21
【问题描述】:
我目前正在为我的 Angular 项目使用 Karma 测试运行程序,以及 jasmine 测试框架。它工作得很好,但我有一个问题:当对象比较失败时,打印到控制台中的结果真的很难阅读,并且这些对象具有的属性越多就越难。示例:
Expected spy spy to have been called with [ { currentCareMoment : { ID : 5, Description : 'Late namiddag (16-20)', StartHour : 16, EndHour : 20 }, previousCareMoment : { ID : 4, Description : 'Namiddag (14-16)', StartHour : 14, EndHour : 16 } } ] but actual calls were [ { currentCareMoment : { ID : 6, Description : 'Avond (20-24)', StartHour : 20, EndHour : 24 }, previousCareMoment : { ID : 5, Description : 'Late namiddag (16-20)', StartHour : 16, EndHour : 20 } } ].
无论如何设置 Jasmine(我认为 Karma 与它无关)来打印更漂亮的对象?只是一些换行符和缩进已经是一个巨大的帮助。示例:
Expected spy spy to have been called with [ {
currentCareMoment : {
ID : 5,
Description : 'Late namiddag (16-20)',
StartHour : 16,
EndHour : 20
},
previousCareMoment : {
ID : 4,
Description : 'Namiddag (14-16)',
StartHour : 14,
EndHour : 16
}
} ] but actual calls were [ {
currentCareMoment : {
ID : 6,
Description : 'Avond (20-24)',
StartHour : 20,
EndHour : 24
},
previousCareMoment : {
ID : 5,
Description : 'Late namiddag (16-20)',
StartHour : 16,
EndHour : 20
}
} ].
【问题讨论】:
-
可能重复stackoverflow.com/questions/23429709/… 但不幸的是,目前没有解决方案
-
尝试使用 node.js :util.inspect