-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Proposal: add snapshot testing (this is not screenshot diffing) #772
Comments
Loving this. Can we also add it for elements? // should serialize the HTML as a string and inline
// certain things like value, checked, selected, etc
cy.get('form').snapshot() Bonus points if you format the HTML nicely 👍 |
It is already there - the focused().snapshot() is an example. Instead of HTML it converts DOM to json though
…Sent from my iPhone
On Oct 19, 2017, at 13:18, Brian Mann ***@***.***> wrote:
Loving this. Can we also add it for elements?
cy.get('form').snapshot() // should serialize the HTML as a string and inline certain things like value, checked, selected, etc
Bonus points if you format the HTML nicely 👍
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I see... is this what jest does as opposed to string HTML? |
I think Jest converts to HTML, but I am not sure. But I think this is great user space feature, so I can make this public under |
I want to see this in cypress core... it's incredibly useful and powerful for a myriad of things. Using the console as a comparison is super nice to explore the object structures. We could even potentially compare the HTML using the actual application under test by inlining all of the styles or capturing them as well separately and applying the styles to the elements. |
Yes!!!
…Sent from my iPhone
On Oct 19, 2017, at 13:34, Brian Mann ***@***.***> wrote:
I want to see this in cypress core... it's incredibly useful and powerful for a myriad of things.
Using the console as a comparison is super nice to explore the object structures.
We could even potentially compare the HTML using the actual application under test by inlining all of the styles or capturing them as well separately and applying the styles to the elements.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Just wanted to bring up that we use the terminology 'snapshot' for explaining the 'time-travel' process of restoring the DOM when hovering over commands and 'pinning' - we will have to rename this to something else, since I think most people define 'snapshots' as the feature explained in this proposal. |
Yes @jennifer-shehane. New to Cypress, and every time I read snapshot in the docs, I thought it had support for jest snapshots, which I thought was awesome. Seeing that is uses chai is what led me here. |
We use Jest for the rest of our testing, so if Cypress could integrate with Jest that would be awesome. |
We use Ava across our applications. Any Cy + ava examples? |
Interestingly there doesn't seem to have any good solution for json/data snapshots that is maintained for cypress 10+ and cypress mentioned 5 years ago that it's a plan to get it to the core https://www.cypress.io/blog/2018/01/16/end-to-end-snapshot-testing/. |
Any progress on this, or if it has been replaced with a 3rd party plugin or a different approach, what would that be? I want to incorporate this testing approach to my project and I was wondering what would be the latest best practices around it. |
Similar to Jest / Ava snapshot testing (see https://glebbahmutov.com/blog/snapshot-testing/ and https://glebbahmutov.com/blog/picking-snapshot-library/) it would be nice to save / compare values to snapshots.
For example this test can save the wrapped objects on the first run, then we would check in the generated
snapshots.js
file. Next time Cypress runs it would compare new values with saved snapshots and throw an error if they are different.Here is a proof of concept
The test runner
When clicking on "snapshot" in the reporter, it shows the object in the dev tools
Similarly, if previous command yields a jQuery element, then it is converted into JSON and saved. For example, we could snapshot focused element before and after typing (TodoMVC example at todomvc.com/examples/react/)
When clicking on the snapshot in this case, prints original element and JSON object
The snapshots are all loaded at the start and saved together at the end. Here is snapshot file
If a run time value during test does not match value loaded from snapshot, it throws an exception.
For example, changed code to
cy.wrap({foo: 45}).snapshot()
leads toThe text was updated successfully, but these errors were encountered: