|
13 | 13 | <p>Simple and complete Svelte testing utilities that encourage good testing practices.</p>
|
14 | 14 |
|
15 | 15 | [**Read The Docs**](https://testing-library.com/docs/svelte-testing-library/intro) |
|
16 |
| -[Edit the docs](https://github.com/alexkrolick/testing-library-docs) |
| 16 | +[Edit the docs](https://github.com/testing-library/testing-library-docs) |
17 | 17 |
|
18 | 18 | <!-- prettier-ignore-start -->
|
19 | 19 | [![Build Status][build-badge]][build]
|
@@ -80,19 +80,42 @@ This library has `peerDependencies` listings for `svelte >= 3`.
|
80 | 80 | You may also be interested in installing `@testing-library/jest-dom` so you can use
|
81 | 81 | [the custom jest matchers](https://github.com/testing-library/jest-dom).
|
82 | 82 |
|
| 83 | +## Setup |
| 84 | + |
| 85 | +We recommend using `@testing-library/svelte` with [Vitest][] as your test runner. To get started, add the `svelteTesting` plugin to your Vite or Vitest config. |
| 86 | + |
| 87 | +```diff |
| 88 | + // vite.config.js |
| 89 | + import { svelte } from '@sveltejs/vite-plugin-svelte' |
| 90 | ++ import { svelteTesting } from '@testing-library/svelte/vite' |
| 91 | + |
| 92 | + export default defineConfig({ |
| 93 | + plugins: [ |
| 94 | + svelte(), |
| 95 | ++ svelteTesting(), |
| 96 | + ] |
| 97 | + }); |
| 98 | +``` |
| 99 | + |
| 100 | +See the [setup docs][] for more detailed setup instructions, including for other test runners like Jest. |
| 101 | + |
| 102 | +[vitest]: https://vitest.dev/ |
| 103 | +[setup docs]: https://testing-library.com/docs/svelte-testing-library/setup |
| 104 | + |
83 | 105 | ### Svelte 5 support
|
84 | 106 |
|
85 | 107 | If you are riding the bleeding edge of Svelte 5, you'll need to either
|
86 |
| -import from `@testing-library/svelte/svelte5` instead of `@testing-library/svelte`, or have your `vite.config.js` contains the following alias: |
| 108 | +import from `@testing-library/svelte/svelte5` instead of `@testing-library/svelte`, or add an alias to your `vite.config.js`: |
87 | 109 |
|
88 |
| -``` |
89 |
| -export default defineConfig(({ }) => ({ |
| 110 | +```js |
| 111 | +export default defineConfig({ |
| 112 | + plugins: [svelte(), svelteTesting()], |
90 | 113 | test: {
|
91 | 114 | alias: {
|
92 |
| - '@testing-library/svelte': '@testing-library/svelte/svelte5' |
93 |
| - } |
| 115 | + '@testing-library/svelte': '@testing-library/svelte/svelte5', |
| 116 | + }, |
94 | 117 | },
|
95 |
| -})) |
| 118 | +}) |
96 | 119 | ```
|
97 | 120 |
|
98 | 121 | ## Docs
|
|
0 commit comments