Intro
Svelte Testing Library on GitHub
npm install --save-dev @testing-library/svelte
This library is built on top of
DOM Testing Library
which is where most of the logic behind the queries is.
The Problem
You want to write tests for your Svelte components so that they avoid including implementation details, and are maintainable in the long run.
This Solution
The Svelte Testing Library is a very lightweight solution for testing Svelte
components. It provides light utility functions on top of svelte
, in a way
that encourages better testing practices. Its primary guiding principle is:
The more your tests resemble the way your software is used, the more confidence they can give you.
So rather than dealing with instances of rendered Svelte components, your tests will work with actual DOM nodes. See the Dom Introduction for a more in-depth explanation.
What this library is not:
- A test runner or framework.
- Specific to a testing framework.
We recommend Jest as our preference.