Skip to content

Instantly share code, notes, and snippets.

@adamliptrot-oc
Created August 1, 2024 13:20
Show Gist options
  • Select an option

  • Save adamliptrot-oc/71c4d7fd2af8141e83e83d4b4ac3039f to your computer and use it in GitHub Desktop.

Select an option

Save adamliptrot-oc/71c4d7fd2af8141e83e83d4b4ac3039f to your computer and use it in GitHub Desktop.
Visual regression testing with Cypress
const baseUrl = "https://liptrot.org";
const sizes = [[600, 900]]
const pages = [
{url:"/",name:"home"},
{url: "/guides", name:"guides"},
{url: "/posts/accessible-names/", name:"blog-accessible-names"}
]
sizes.forEach((size) => {
describe(`On ${size} screen`, () => {
pages.forEach((page) => {
it(`Render ${page.name}`, () => {
if (Cypress._.isArray(size)) {
cy.viewport(size[0], size[1])
} else {
cy.viewport(size)
}
cy.visit(siteUrl + page.url)
cy.compareSnapshot(`${page.name}-${size}`)
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment