The main requirements on a snapshot name string are:
It must be unique. Each snapshot in your test suite should have a different name.
It must remain stable between test runs. This is so that Percy can compare snapshot versions and catch any changes.
The code examples below assume that you're using the [Percy Puppeteer SDK](🔗), but the instructions here would work for other Percy SDKs as well.
# One snapshot per test case
In Mocha, you can access the properties of the currently-running test, including its full name, via the `
this.test` object. Using this for naming a Percy snapshot would look like:
For Jasmine **versions before 2.0,** you can use `
jasmine.getEnv().currentSpec` to get the name of the current spec. Using that together with Percy would look like:
For Jasmine **versions after 2.0**, `
jasmine.getEnv().currentSpec` is no longer supported. In these versions, you can get the current Jasmine spec name assigning your current `
it` block to a variable and then querying it for its full name:
If you're using the [Percy Cypress SDK](🔗), Percy will automatically use the name of the current test for you if you don't pass in a snapshot name:
If you want to access the test name yourself (for example, to manipulate it before passing it to Percy, or because you want to pass additional options), you can do so using `
## Multiple snapshots per test case
In the cases when you are taking multiple Percy snapshots in the same test case, you can't rely entirely on using the test's name, as that will generate two different snapshots with the same name, and Percy will reject the second one.
In this situation, you can use an autogenerated snapshot name for the first call, and append a descriptive string to the autogenerated names for subsequent snapshot calls. For example, in Cypress: