12 Testing

 

This chapter covers

  • Unit tests with Jest
  • End-to-end tests with Cypress
  • Accessibility tests with the Svelte compiler, Lighthouse, axe, and WAVE
  • Demonstrating and debugging Svelte components with Storybook

Now that we’ve covered most of the features of Svelte, it’s time to turn our focus to testing. We want to feel confident that our applications have properly implemented their intended functionality in a way that is accessible to a variety of users and that will remain that way through repeated updates. Three primary kinds of tests to consider are unit, end-to-end, and accessibility.

Unit tests are intended to test a piece of code in isolation from the rest of an application. These are great for testing individual functions and components. We will cover implementing unit tests using the Jest testing framework.

End-to-end tests are intended to test an application in the same way that a user would interact with it. This includes logging in (if the app requires it), navigating to each page within the app (if there are multiple pages), and generally putting the app into each of the states a user would encounter. We will cover implementing end-to-end tests using the Cypress testing framework.

12.1 Unit tests with Jest

12.1.1 Unit tests for the Todo app

12.1.2 Unit tests for the Travel Packing app

12.2 End-to-end tests with Cypress

12.2.1 End-to-end tests for the Todo app

12.2.2 End-to-end tests for the Travel Packing app

12.3 Accessibility tests

12.3.1 Svelte compiler

12.3.2 Lighthouse

12.3.3 axe

12.3.4 WAVE

12.4 Component demos and debugging with Storybook

12.4.1 Storybook for Travel Packing app

Summary