question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Snapshot comparison never fails

See original GitHub issue

I have been following the README step by step. Here is the state of my dummy project: Repo

I wrote this test: File

cy.visit("localhost:3000")
      .document()
      .toMatchImageSnapshot();

Running that test causes a screenshot to be saved. However, when I change what is rendered on the page, the tests still pass!

Expected result: Screen Shot 2019-08-16 at 4 24 42 PM


Actual result: Screen Shot 2019-08-16 at 4 24 50 PM


I do not understand why the tests pass, if what is rendered in cypress’ browser looks different than the screenshot that is saved.

I do not understand how toMatchImageSnapshot works. What is the base image that it uses? What is the current image?

Could someone please advise me how to get this test failing as expected?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:11

github_iconTop GitHub Comments

25reactions
wolfi3bcommented, Nov 20, 2019

[NOTE: My first message (I deleted to remove confusion) was incorrect due to forgotten testing code]

So guys (FYI @meinaart) …It bothered me so I digged deep down to the code and found the issue 😃

The problem is simple… we are using it wrong.

In documentation is writen simply

You can pass the following options to toMatchImageSnapshot to override default behavior.

followed up by example

{
  "createDiffImage": true,       // Should a "diff image" be created, can be disabled for performance
  "threshold": 0.01,             // Amount in pixels or percentage before snapshot image is invalid
  "name": "custom image name",   // Naming resulting image file with a custom name rather than concatenating test titles
  "thresholdType": "percent",    // Can be either "pixel" or "percent"
}

so it evokes we should put it directly to “toMatchImageSnapshot” function. But that is not correct.

in config.js is code which expects

return Object.keys(DEFAULT_IMAGE_CONFIG)
    .filter((key) => options.imageConfig && options.imageConfig[key] !== undefined)
    .reduce(

so actually correct call to the method is:

cy.get('.class').toMatchImageSnapshot({imageConfig: {"threshold": 0})

and voala…it finally fails at not matching screenshots!

3reactions
StormPoopercommented, Jan 7, 2020

Nice find @wolfi3b, it also seems to fix it if there’s a value in your cypress.json file, like so:

{
  "env": {
    "cypress-plugin-snapshots": {
      "imageConfig": {
        "threshold": 0.01
      }
    }
  },
  "ignoreTestFiles": [
    "**/__snapshots__/*",
    "**/__image_snapshots__/*"
  ]
}

Side note, my instance would blow up unless I included cypress-plugin-snapshots in my config. I’m guessing the code for checking defaults isn’t quite right based on both of these issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snapshot comparison - Virtuoso Guide
Snapshot comparison allows you to compare screenshots between previous and current versions of your application. It is useful for spotting ...
Read more >
SQL Compare Snapshots: a lightweight database version ...
... SQL Compare Snapshots offer an easy way to work out what broke, if a change causes some tests to fail, as well...
Read more >
Compare two localsnapshots in APFS | Apple Developer Forums
I found the compare verb in tmutil requires a snapshot path, but the localsnapshot is ... Not sure if you ever found an...
Read more >
Isilon Quick Tips: Compare Snapshots - YouTube
DATA ENGINEER RESOURCE - Site devoted to "BUILDING STRONGER DATA ENGINEERS" ◅https://thomashenson.com▻ ASK BIG DATA BIG QUESTION - Submit ...
Read more >
Isilon Quick Tips: Compare Snapshots in OneFS
Whatever the case OneFS has the ability to compare snapshots from ... to subscribe so that you never miss an episode of Isilon...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found