
Interactive Snapshot Mode įailed snapshots can also be updated interactively in watch mode: You can try out this functionality by cloning the snapshot example, modifying the Link component, and running Jest. If you'd like to limit which snapshot test cases get re-generated, you can pass an additional -testNamePattern flag to re-record snapshots only for those tests that match the pattern. If we had any additional failing snapshot tests due to an unintentional bug, we would need to fix the bug before re-generating snapshots to avoid recording snapshots of the buggy behavior. This will re-generate snapshot artifacts for all failing snapshot tests. You may also use the equivalent single-character -u flag to re-generate snapshots if you prefer. Go ahead and accept the changes by running the above command. One such situation can arise if we intentionally change the address the Link component in our example is pointing to. Now, let's talk about the case when a snapshot test is failing due to an intentional implementation change. When that happens, go ahead and fix the issue and make sure your snapshot tests are passing again. It's straightforward to spot when a snapshot test fails after a bug has been introduced. We also recommend watching this egghead video on Snapshot Testing with Jest. We recommend reading this blog post to get a good sense of when you should use snapshot testing. More information on how snapshot testing works and why we built it can be found on the release blog post. Also, rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. This implies that even if any other file has missing props (Say, App.js) in the component, it will still pass the test as the test doesn't know the usage of component and it's scoped only to the Link.js. Note: The snapshot is directly scoped to the data you render – in our example the component with page prop passed to it.
Creating a facebook app wrapper page code#
If they don't match, either the test runner found a bug in your code (in the component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated.
:max_bytes(150000):strip_icc()/facebook-offers-information-1240619-1-45937c65f07e4df48020cb2ef06bbcc5.jpg)
On subsequent test runs, Jest will compare the rendered output with the previous snapshot. Jest uses pretty-format to make snapshots human-readable during code review. The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process.
