This chapter covers multiple ways to test Svelte applications. These include:
- 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 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 page), 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.