You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 28, 2023. It is now read-only.
For example, if I wanted to create a serializer that would reverse an html string (simple, contrived example), it would look like this:
module.exports={test: function(received){// if true, it runs the print functionreturntypeof(received)==='string'&&received.startsWith('<');},print: function(received){returnreceived.split('').reverse().join('');}}
The flow for this is:
A test has some type of expectation, like so: expect(INPUT).toMatchSnapshot();
The INPUT is passed to the serializer, as is, (number, object, string, whatever)
Run the serializer test function with the INPUT to see if it is a type of data it wants to serialize
If the serializer test returns truthy, then run the serializer print function passing in the INPUT
When the serializer finishes it returns a modified version of the INPUT
If another serializer was defined in the array in the config, repeat the process
@cypress/snapshot then either stores the modified value, or compares against the existing stored value.
With this, plugins can can made for specific frameworks (Vue, Angular, React, etc) to improve their snapshots.
PLEASE keep the api the same as what Jest uses, so I don't need to maintain two libraries to do the same thing.
As he's a library maintainer for a snapshot lib, @TheJaredWilcurt may be interested in contributing to Cypress's core snapshotting solution when time allows
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Jest allows you to specify the location of a "snapshot serializer" file. This gives users the power to format the snapshots however they like.
For example, if I wanted to create a serializer that would reverse an html string (simple, contrived example), it would look like this:
The flow for this is:
expect(INPUT).toMatchSnapshot();
INPUT
is passed to the serializer, as is, (number, object, string, whatever)test
function with theINPUT
to see if it is a type of data it wants to serializetest
returnstruthy
, then run the serializerprint
function passing in theINPUT
@cypress/snapshot
then either stores the modified value, or compares against the existing stored value.With this, plugins can can made for specific frameworks (Vue, Angular, React, etc) to improve their snapshots.
PLEASE keep the api the same as what Jest uses, so I don't need to maintain two libraries to do the same thing.
In fact, if you make this work, I'll rename my repo to
snapshot-serializer-vue
since it will work in both Jest and Cypress.The text was updated successfully, but these errors were encountered: