- Notifications
You must be signed in to change notification settings - Fork32
🐿️ Simple and complete Svelte DOM testing utilities that encourage good testing practices
License
testing-library/svelte-testing-library
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation

Simple and complete Svelte testing utilities that encourage good testing practices.
You want to write maintainable tests for yourSvelte components.
@testing-library/svelte is a lightweight library for testing Sveltecomponents. It provides functions on top ofsvelte and@testing-library/dom so you can mount Svelte components and query theirrendered output in the DOM. Its primary guiding principle is:
The more your tests resemble the way your software is used, the moreconfidence they can give you.
This module is distributed vianpm which is bundled withnode andshould be installed as one of your project'sdevDependencies:
npm install --save-dev @testing-library/svelte
This library supportssvelte versions3,4, and5.
You may also be interested in installing@testing-library/jest-dom so you canusethe custom jest matchers.
We recommend using@testing-library/svelte withVitest as your testrunner. To get started, add thesvelteTesting plugin to your Vite or Vitestconfig.
// vite.config.js import { svelte } from '@sveltejs/vite-plugin-svelte'+ import { svelteTesting } from '@testing-library/svelte/vite' export default defineConfig({ plugins: [ svelte(),+ svelteTesting(), ] });See thesetup docs for more detailed setup instructions, including for othertest runners like Jest.
In Vitest (via thesvelteTesting plugin) and Jest (via thebeforeEach andafterEach globals),this library will automatically setup and cleanup the test environment before and after each test.
To do your own cleanup, or if you're using another framework, call thesetup andcleanup functions yourself:
import{cleanup,render,setup}from'@testing-library/svelte'// beforesetup()// testrender(/* ... */)// aftercleanup()
To disable auto-cleanup in Vitest, set theautoCleanup option of the plugin to false:
svelteTesting({autoCleanup:false})
To disable auto-cleanup in Jest and other frameworks with global test hooks,set theSTL_SKIP_AUTO_CLEANUP environment variable:
STL_SKIP_AUTO_CLEANUP=1 jest
See thedocs over at the Testing Library website.
Looking to contribute? Look for theGood First Issuelabel.
Please file an issue for bugs, missing documentation, or unexpected behavior.
Please file an issue to suggest new features. Vote on feature requests by addinga 👍. This helps maintainers prioritize what to work on.
For questions related to using the library, please visit a support communityinstead of filing an issue on GitHub.
Thanks goes to these people (emoji key):
This project follows theall-contributors specification.Contributions of any kind welcome!
About
🐿️ Simple and complete Svelte DOM testing utilities that encourage good testing practices
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.