You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/07-misc/02-testing.md
+7-39Lines changed: 7 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -250,39 +250,11 @@ When writing component tests that involve two-way bindings, context or snippet p
250
250
251
251
_With Storybook_
252
252
253
-
[Storybook](https://storybook.js.org?ref=svelte-docs) is the industry standard for developing and documenting UI components, and it can also be used to test your components. A storybook is made up of [stories](https://storybook.js.org/docs/writing-stories?ref=svelte-docs&renderer=svelte)—isolated examples of your components in different states and with simulated interactions. These stories can also function as [component tests](https://storybook.js.org/docs/writing-tests?ref=svelte-docs&renderer=svelte), with no additional code needed. They're run with Vitest's browser mode, which renders your components in a real browser for the most realistic testing environment.
253
+
[Storybook](https://storybook.js.org) is a tool for developing and documenting UI components, and it can also be used to test your components. They're run with Vitest's browser mode, which renders your components in a real browser for the most realistic testing environment.
254
254
255
-
To get started, first install Storybook ([using Svelte's CLI](/docs/cli/storybook)) in your project if you haven't already:
255
+
To get started, first install Storybook ([using Svelte's CLI](/docs/cli/storybook)) in your project via `npx sv add storybook` and choose the recommended configuration that includes testing features. Else follow the [Storybooks docs](https://storybook.js.org/docs/get-started/frameworks/svelte-vite#getting-started) on getting started.
256
256
257
-
```sh
258
-
npx sv add storybook
259
-
```
260
-
261
-
When prompted, choose the recommended configuration that includes testing features.
262
-
263
-
If you already have Storybook set up, but are not yet using the testing features, first upgrade to the latest version:
264
-
265
-
```sh
266
-
npx storybook@latest upgrade
267
-
```
268
-
269
-
Then, install and configure Storybook's Vitest addon:
270
-
271
-
```sh
272
-
npx storybook add @storybook/addon-vitest
273
-
```
274
-
275
-
That `add` command will install and register the Vitest addon. It will also inspect your project's Vite and Vitest setup, and install and configure them with sensible defaults, if necessary. You may need to adjust the [configuration](https://storybook.js.org/docs/writing-tests/integrations/vitest-addon?ref=svelte-docs&renderer=svelte#options) to fit your project's needs.
276
-
277
-
When you run Storybook, you will see a test widget in the bottom of your sidebar, from where you can run your tests. Each story is automatically transformed into a test. The results will be shown in the sidebar and you can debug your tests using Storybook's tools and the browser devtools. You can also integrate [accessibility tests](https://storybook.js.org/docs/writing-tests/accessibility?ref=svelte-docs&renderer=svelte), which will run alongside your component tests.
278
-
279
-
You can also run those component tests in the terminal (and in CI) using the Vitest CLI.:
280
-
281
-
```sh
282
-
npx vitest --project storybook
283
-
```
284
-
285
-
You can create stories for component variations and test interactions with the [play function](https://storybook.js.org/docs/writing-tests/interaction-testing?ref=svelte-docs&renderer=svelte#writing-interaction-tests), which allows you to simulate behavior and make assertions using the Testing Library and Vitest APIs. Here's an example of two stories that can be tested, one that renders an empty Form component and one that simulates a user filling out the form:
257
+
You can then create stories for component variations and test interactions with the [play function](https://storybook.js.org/docs/writing-tests/interaction-testing?renderer=svelte#writing-interaction-tests), which allows you to simulate behavior and make assertions using the Testing Library and Vitest APIs. Here's an example of two stories that can be tested, one that renders an empty Form component and one that simulates a user filling out the form:
286
258
287
259
```svelte
288
260
/// file: LoginForm.stories.svelte
@@ -295,7 +267,7 @@ You can create stories for component variations and test interactions with the [
295
267
const { Story } = defineMeta({
296
268
component: LoginForm,
297
269
args: {
298
-
// 👇 Pass a mock function to the `onSubmit` prop
270
+
// Pass a mock function to the `onSubmit` prop
299
271
onSubmit: fn(),
300
272
}
301
273
});
@@ -306,23 +278,19 @@ You can create stories for component variations and test interactions with the [
When you view that story or run that test in Storybook, you can see each step of the simulated behavior and the assertions made against the component. If anything goes wrong, you can step back-and-forth through the test to pinpoint exactly where the issue occurred.
324
-
325
-
To learn more about Storybook's mocking, accessibility testing, interactions debugging, and coverage tools, please see the [Storybook testing docs](https://storybook.js.org/docs/writing-tests?ref=svelte-docs&renderer=svelte).
293
+
To learn more about Storybook's mocking, accessibility testing, interactions debugging, and coverage tools, please see the [Storybook testing docs](https://storybook.js.org/docs/writing-tests?renderer=svelte).
0 commit comments