Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toEqual reports detailed comparison of objects and arrays - take 2 #1163

Merged
merged 1 commit into from
Nov 17, 2016

Conversation

benchristel
Copy link

@benchristel benchristel commented Jul 21, 2016

This implements #675. It addresses @slackersoft's comments on #1042, which was my first attempt at implementing this feature.

EDIT: This is now "done" and ready for review.

I'm opening a PR for it because I'd love to get some intermediate feedback on the approach. I keep discovering edge cases that seem to require refactoring within eq to enable adding the diff functionality, and want to make sure I'm not going down the wrong path or inadvertently changing behavior. Also, any feedback about the preferred format for these error messages would be immensely helpful at this stage.

Thanks in advance for any feedback you have time to provide. I'll keep working on this in the meantime since I'm between projects at Pivotal Labs for the next week.

@benchristel
Copy link
Author

@slackersoft, @Gerg —it looks like the discussion on #675 never reached a consensus about whether to pretty-print the entire object if there's a deeply-nested mismatch. The code in this PR currently does not (in general) print the whole object.

I considered the idea of adding the pretty-print but greatly limiting the length and depth to which the objects would be printed, by passing MAX_PRETTY_PRINT_DEPTH and MAX_PRETTY_PRINT_ARRAY_LENGTH as parameters to the printer. Would you be OK with that?

@jeromecovington
Copy link

I know "plus one-ing" is not the most helpful comment to a conversation, but getting detailed comparisons to expected data would really be helpful. This is a real pain point when working with large objects, sometimes deeply nested. So +1. ;-)

@ghost
Copy link

ghost commented Aug 31, 2016

@benchristel even if there is no concensus I would argue that anything is better than the current state. Manually comparing large objects is a real pain right now. I am eagerly looking forward to this feature.

@jgrund
Copy link

jgrund commented Oct 3, 2016

Any update on this? Sorely needed when comparing large objects.

@mehdi-d
Copy link

mehdi-d commented Oct 17, 2016

Any update on this?

@surdu
Copy link

surdu commented Oct 28, 2016

How can we beta test this before it's released ?

Tried to npm install this as the jasmine-core in my local jasmine installation, but doesn't appear to work as I still see the old style diff.

Also, will this also work for strings ?

@benchristel benchristel force-pushed the eq-diffs branch 2 times, most recently from fc82f87 to 295551c Compare November 4, 2016 04:02
@benchristel
Copy link
Author

@surdu sorry, I hadn't run grunt buildDistribution, which builds the jasmine.js file from the src files. I've done it now, so you should be able to npm install from this branch and see the new diff behavior.

Currently, it does not do anything special for strings. I don't think it would be too hard to add string-diffing, but maybe it should wait for a future PR.


expect(compareEquals(actual, expected).message).toEqual(message);
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a bunch of xitd specs below here. We should either implement them or pull them out as not relevant

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xitd specs have been implemented. The one for custom equality checkers turned into an integration test.

return false;
}
var iterA = a.values(), iterB = b.values();
var valA, valB;
do {
valA = iterA.next();
valB = iterB.next();
if (!eq(valA.value, valB.value, aStack, bStack, customTesters)) {
if (!eq(valA.value, valB.value, aStack, bStack, customTesters, j$.NullDiffBuilder())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the diffBuilder local and not grabbing a new NullDiffBuilder?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in the NullDiffBuilder will cause both Sets to be pretty-printed in the failure message of their containing object. Basically, I was uncertain about how to display set diffs, so I just punted on this one.

Ideally, I'd like something similar to the diff that's displayed for objects when a and b have different sets of keys. However, the way set equality is implemented right now, the insertion order of items in the set matters. Given that that's the case, we could treat sets like arrays. But that, too, presents problems, because then you'd get output like

Expected $[0] to equal 'bar', but got 'baz'

when the objects in question are Sets, not Arrays. This output seems a bit misleading since set items can't actually be accessed by index.

- Mismatches deep within object/array structures are pinpointed with a JsonPath-like syntax.
@slackersoft slackersoft merged commit d5e6bf4 into jasmine:master Nov 17, 2016
slackersoft pushed a commit that referenced this pull request Nov 17, 2016
@surdu
Copy link

surdu commented Nov 18, 2016

Merged! 🎉

So, did it finally also included big strings in the diff or only big objects ?

@slackersoft
Copy link
Member

@benchristel It looks like this actually has some failing tests in the various IE browsers. If you, or someone else, have some time to look into the failures (https://travis-ci.org/jasmine/jasmine/builds/176577479) we need to get these fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants