Chapter 12. Writing snapshot tests

 

This chapter covers

  • Understanding snapshot tests
  • Adding snapshot tests to your workflow
  • Writing snapshot tests for components

In this chapter, you’ll learn what snapshot tests are, how they fit in to the testing workflow, and how to use them to make sure components aren’t changed unintentionally.

Definition

Snapshot testing is a way of comparing two pictures of an application automatically.

Up until this chapter, you’ve learned to write unit tests. Now it’s time to add a new type of test to your testing tool belt. If you remember from back in chapter 1, I showed you how to use the frontend pyramid as a guide for how to structure a test suite (figure 12.1). The next type of tests in the pyramid after unit tests are snapshot tests.

Figure 12.1. The frontend testing pyramid

In the first section of this chapter, you’ll learn what snapshot testing is. When you’ve got an understanding of it, I’ll show you how it fits into your testing workflow and how you can use snapshot tests to catch unintended changes to components

In the second section of the chapter, you’ll learn how to write effective snapshot tests for both static and dynamic components.

Before you go further, you need to download the finished chapter-12 application. This application has new views that I added outside of this book. Follow the instructions in appendix A to download the Git repository if you haven’t already, and switch to the chapter-12 branch.

12.1. Understanding snapshot tests

12.2. Adding snapshot tests to your workflow

Summary

Exercises

sitemap