karma/jasmine console more detailed test results

和自甴很熟 提交于 2019-12-22 11:42:11

问题


I'm using Karma with Jasmine for my javascript unit tests. Suppose I have a failing test like this:

 expect(objectA).toEqual(expectedObjectA);

When it fails, I see the two objects dumped on the console and a message telling me the objects are not equal:

This is not very helpful because in order to find out why they are not equal, I have to to copy paste the text from the console, split the two objects from that object dump, format them, put them in a diff editor. (Sometimes even that doesn't help because the object are not equal because they have members which are functions).

Is there a way to make jasmine dump to the console the exact name and value of the first property that differs between the two objects?

Is there a way to see the object dump pretty printed? (not really necessary, but it would be nicer than this unreadable dump)


回答1:


Looks like you may need a custom matcher.
Have you had a look at this question ? Jasmine toEqual for complex objects (mixed with functions)



来源:https://stackoverflow.com/questions/24076429/karma-jasmine-console-more-detailed-test-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!