Skip to main content

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-testing-library for a more in-depth explanation.

What this library is not:

  1. A test runner or framework.
  2. Specific to a testing framework.