-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
assert.deepStrictEqual diff confusion #22763
Comments
On a related note, I think it's even more confusing when |
This is already on my ToDo list. I had a look at proper diffing algorithms and I'll add that when I find a bit more time. The output could still be improved a lot. This was a quick and simple implementation that improved the former situation a lot and that's why I went for that first. I'll have a thought about |
The order option can be used to sort the inspected values in case they do not rely on their order as arrays. That way the output is stable no matter of the object property inspection order. PR-URL: nodejs#22788 Refs: nodejs#22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. PR-URL: nodejs#22788 Refs: nodejs#22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
The order option can be used to sort the inspected values in case they do not rely on their order as arrays. That way the output is stable no matter of the object property inspection order. PR-URL: nodejs#22788 Refs: nodejs#22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Assertion errors that produce a diff show a diff for identical entries in case one side of the comparison has more object properties than the other one. Those lines are now taken into account and will not show up as diverging lines anymore. Refs: nodejs#22763
@targos looking at your comment about
What do you think would be a good output in case of two diverging objects that are not reference equal? Only showing the actual or expected object or not showing any at all removes important information for the user. So the only thing I can think about right now that might improve the situation would be to show both objects at the same time (which the current situation should actually already solve by having a combined view that reduces the overall output length). Would a different message instead already help? E.g., I would only use that message for objects and not when comparing primitives. |
In case reference (un)equal objects fail in assertion, it should be clear that it is about the reference equality and not about the object properties. This is fixed by improving the message in such cases. Refs: nodejs#22763
The order option can be used to sort the inspected values in case they do not rely on their order as arrays. That way the output is stable no matter of the object property inspection order. Backport-PR-URL: #23039 PR-URL: #22788 Refs: #22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. PR-URL: nodejs#22788 Refs: nodejs#22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
In case reference (un)equal objects fail in assertion, it should be clear that it is about the reference equality and not about the object properties. This is fixed by improving the message in such cases. Refs: nodejs#22763 PR-URL: nodejs#23056 Refs: nodejs#22763 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The wording seems clearer when using `values` instead of `inputs`. PR-URL: nodejs#23056 Refs: nodejs#22763 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Assertion errors that produce a diff show a diff for identical entries in case one side of the comparison has more object properties than the other one. Those lines are now taken into account and will not show up as diverging lines anymore. Refs: nodejs#22763 PR-URL: nodejs#23048 Refs: nodejs#22763 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
It became hard to follow what was actually happening in the algorithm. This adds comments to improve the situation. PR-URL: nodejs#23048 Refs: nodejs#22763 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Thanks for the fixes @BridgeAR ! |
@targos you are welcome but for me this is still work in progress. There are still a couple of cases that will not produce a nice diff. It is just not that trivial to solve. This applies especially to more complex nested objects. I am going to work on it either way but we could just this issue open as reference point. |
OK, I can reopen. Can you update the OP or post a message with an example that is still problematic? |
Done. I just updated your post :) |
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. PR-URL: nodejs#22788 Refs: nodejs#22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. Backport-PR-URL: #23226 PR-URL: #22788 Refs: #22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. Backport-PR-URL: #23226 PR-URL: #22788 Refs: #22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
I'm closing this. The current output is not strictly wrong |
See these examples:
First:
It should actually print:
Second example:
Should be:
Already fixed part
I think I would expect more something like this:
The text was updated successfully, but these errors were encountered: