Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐿️ Simple and complete Svelte DOM testing utilities that encourage good testing practices

License

NotificationsYou must be signed in to change notification settings

testing-library/svelte-testing-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
chipmunk

Simple and complete Svelte testing utilities that encourage good testing practices.

Read The Docs |Edit the docs |Examples

Build StatusCode CoverageversiondownloadsMIT License

All ContributorsPRs WelcomeCode of ConductDiscord

Watch on GitHubStar on GitHubTweet


Table of Contents

The Problem

You want to write maintainable tests for yourSvelte components.

This Solution

@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.

Installation

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.

Setup

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.

Auto-cleanup

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

Docs

See thedocs over at the Testing Library website.

Issues

Looking to contribute? Look for theGood First Issuelabel.

🐛 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

See Bugs

💡 Feature Requests

Please file an issue to suggest new features. Vote on feature requests by addinga 👍. This helps maintainers prioritize what to work on.

See Feature Requests

❓ Questions

For questions related to using the library, please visit a support communityinstead of filing an issue on GitHub.

Contributors

Thanks goes to these people (emoji key):

Ben Monro
Ben Monro

💻⚠️🤔📖
Emil Tholin
Emil Tholin

💻⚠️🤔
Eduardo Rabelo
Eduardo Rabelo

⚠️💻📖💡
Tim Deschryver
Tim Deschryver

📖
Emanuele
Emanuele

💻⚠️📖
pngwn
pngwn

💻⚠️
Sebastian Silbermann
Sebastian Silbermann

💻
Rahim Alwer
Rahim Alwer

💻📖⚠️👀
Bob
Bob

🐛💻
Ron Merkin
Ron Merkin

💻
Ben McCann
Ben McCann

⚠️
John Bowser
John Bowser

💻⚠️
Yoann
Yoann

💻
Yanick Champoux
Yanick Champoux

💻
Michael Cousins
Michael Cousins

💻

This project follows theall-contributors specification.Contributions of any kind welcome!


[8]ページ先頭

©2009-2025 Movatter.jp