npm install --save-dev @testing-library/svelte
yarn add --dev @testing-library/svelte
This library is built on top of
DOM Testing Librarywhich is where most of the logic behind the queries is.
You want to write tests for your Svelte components so that they avoid including implementation details, and are maintainable in the long run.
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:
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.