snapshot icon indicating copy to clipboard operation
snapshot copied to clipboard

Rename command "toMatchSnapshot()"

Open bahmutov opened this issue 7 years ago • 3 comments

To better match Jest syntax, based on comment https://www.cypress.io/blog/2018/01/16/end-to-end-snapshot-testing/index.html#comment-3759119610

bahmutov avatar Feb 15 '18 14:02 bahmutov

I agree that this renaming would theoretically make sense because it follows jest. But I also think that it wouldn't fit the cypress context.

Jest

expect(shallow(<Component />)).toMatchSnapshot()

Cypress

cy.wrap(object).toMatchSnapshot()

This is a semantically incorrect sentence. I'd suggest

cy.wrap(object).shouldMatchSnapshot()

This is still not a full blown sentence, but it adapts to Cypress' should command. Alternative would be

cy.wrap(object).should('match.snapshot')

GerritSe avatar Feb 15 '18 17:02 GerritSe

.should('match.snapshot') is the best fit into the existing command / assertion system.

We would just add a chai assertion to do exactly what toMatchSnapshot does. This would also give you expect(subject).to.match.snapshot

brian-mann avatar Feb 15 '18 18:02 brian-mann

@brian-mann why the addiction to "magic strings"?

alastair-todd avatar Jan 09 '20 11:01 alastair-todd