Skip to content

[Feature]: Fix the naming of toHaveScreenshot by renaming it to toMatchScreenshot #36440

Open
@rkrisztian

Description

@rkrisztian

🚀 Feature Request

In #21632 I don't see a big problem solved, which is the naming of toHaveScreenshot:

[...] the name toHaveScreenshot is ambiguous, why is it named like that? Having a screenshot is something else than matching a screenshot 🤷

toHaveScreenshot name is not clear, it should be updated to something like toMatchScreenshot

My initial reaction when I saw the naming of toHaveScreenshot was like, what is going on here? Playwright supports two kinds of snapshot assertions, one is based on screenshot, the other one can take other data types too, like just text. But they're still doing essentially the same thing: matching snapshots! Usually it makes no sense for webpages to be asserted literally to have a screenshot, because that's not the point of a typical web page! So the naming is a big confusion, it doesn't tell what the purpose of the function is, and it's hard to see quickly that there are two features doing the same thing but with different types of data.

This must change!

Example

Especially because some guides write something like this:

expect(await page.screenshot()).toMatchSnapshot('reference-screenshot.png');

For which, we practically got a shorthand assertion, but named weirdly:

expect(page).toHaveSnapshot('reference-screenshot.png');

This is not in line with the original code's intended meaning, and it will only make sense if it's renamed to toMatchScreenshot.

Motivation

Understanding the differences between the two snapshot assertion methods are hard already as they are. The documentations I currently found did not make it very easy for me to compare the two. Especially because if someone has a Cypress background, they would expect a visual and a JSON-based snapshot matching technique, then you have to check 2 pages:

I would also merge the two guides into one page or structure them differently.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions