问题
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