-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
.should('deep.equal') does not show a full diff comparison on failures #4084
Comments
.should('deep.equal')
does not show a diff on failures
Showing a more detailed diff of objects in the error message is part of this larger issue, that is currently in progress: #3762 You can see an comment on our planned designs there. Will leave this open as part of that epic. You can also click on the |
Thank you Jenniver, Happy to know this is a work in progress! |
Any estimation on when this'll be completed and released? Also, will appreciate any design to write this as a custom method to have this functionality ? |
Thought I'd chime in on this one as the existence of this issue affects my decision to use cypress for REST API testing. |
@jennifer-shehane, is there a technical reason why the two objects aren't diffed? It's a basic feature for most assertion libraries/test runners. Also I see that the related issue is closed, but this problem still exists in 2022. Are there any ways I can hook into the AssertionError and manually produce a diff from the two objects? |
Here is the link for the issue which is still open for the diff feature #3129 Hope this will be addressed soon as its been years since this has been raised |
@Braveheart55 @tsvetan-ganev @gurudattgd04 If you are interested, here is a work-around that a friend of mine (@Bushwazi) came up with that we are using: In our
Notes
It will look like this: I've also been following this issue for 3 years+. I understand Cypress is geared more towards UI-testing than API-testing (For example, I don't need a ViewPort if I'm just testing a JSON REST API, yet there is no flag to turn this off), but they really should start adding some quality of life changes for API-only testing. It would be great if there was an |
@franzvezuli thanks for sharing your workaround! When I try to use it I'm seeing the following
Any ideas what may be wrong? |
You need to throw an error object, something like this should work.
|
@tsonnen-eventus I'm not sure where that code should go. Can you please elaborate on your solution? As an aside without @franzvezuli workaround or any other changes I'm seeing a diff when using the Cypress Netlify plugin in the Netlify deployment logs:
Is it the Cypress plugin that has this logic and if so couldn't it be extended to the web dashboard? |
In the @franzvezuli solution, change
to
|
I had written down a post that chai assertion in cypress not showing the
actual diff and also the solution. Link here
https://www.linkedin.com/posts/gurudatt-s-a-5b892224_cypress-cypressio-testautomation-activity-6903244451108519936-4klR?utm_source=linkedin_share&utm_medium=ios_app
See if this helps
…On Thu, 7 Apr 2022 at 11:44 AM, Tim Sonnen ***@***.***> wrote:
In the @franzvezuli <https://github.com/franzvezuli> solution, change
let diffObject = "expect objects to match:\n";
diffObject += JSON.stringify(diff(str, obj), null, 4)
.replace(/__old/g, "-")
.replace(/__new/g, "+");
throw(diffObject);
to
let diffObject = "expect objects to match:\n";
diffObject += JSON.stringify(diff(str, obj), null, 4)
.replace(/__old/g, "-")
.replace(/__new/g, "+");
let error = new Error(diffObject);
throw error;
—
Reply to this email directly, view it on GitHub
<#4084 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLBBTAIT6KLFAOWIUCWNMLVDZ4LNANCNFSM4HJRN2TQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Unfortunately, that didn't work.
I'll just stick with the Netlify logs that do the diff with magic. |
@jennifer-shehane now that #3762 has been closed (via PR #3930 and #6724), what is left to show the diff of deeply-nested objects? Is this planned for one of the next Cypress versions? |
Seeing this issue open for more than 3 years makes me wonder what people do instead 🤔 |
Does help with this, but there is still so much busy work writing expectations property by property instead of just deep comparing two objects and getting a useful diff on error. |
A note for those trying the code from @franzvezuli json-diff should be installed in the dev dependencies and the code block from #4084 (comment) should be be pasted into /support/e2e.js or similar, see https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Support-file for the new file locations. then the last few lines should be replaced with the code from @tsonnen-eventus but with a renamed variable
Thank you to both of them for providing help. |
4 years in, no luck yet to have it out of the box? |
Ran into this issue today, as wel as no option out of the box to use deep.equalInAnyOrder. Would love to see both in a new version! Helps a lot with (cucumber) reports when a screenshot is made |
I also ran into this problem!
This isn't a very helpful error message. Granted, I can switch to the console to get the error. Any plans to fix this? |
I just had a look at this jsondiffpatch library and realized that the live demo is pretty impressive in terms of diff visuals. Perhaps this could be a possible direction for Cypress especially in the visual GUI runner. |
still facing is there any function equalInAnyOrder for cypress ? |
I've just released a plugin that highlights the difference. Simple installation and usage: https://github.com/elaichenkov/cypress-diff npm i -D cypress-diff // cypress/support/e2e.ts
import 'cypress-diff'; Feel free to open an issue with improvements. Also, don't forget to give it a star. |
Current behavior:
Cypress does not show enough information to know what is the difference when deep comparing complex objects.
Example:
Result:
Desired behavior:
Ideally, I'd like cypress to show a complete diff of the compared objects so we can easily spot the difference.
Versions
[email protected]
The text was updated successfully, but these errors were encountered: