Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Vue 3 Unit testing changes for Portable stories #25528

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { fireEvent, render, screen } from '@testing-library/vue';

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import Meta, { InvalidForm as InvalidFormStory } from './LoginForm.stories'; //👈 Our stories imported here.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { fireEvent, render, screen } from '@testing-library/vue';

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import Meta, { InvalidForm as InvalidFormStory } from './LoginForm.stories'; //👈 Our stories imported here.

Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/vue/multiple-stories-test.3.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { fireEvent, render, screen } from '@testing-library/vue';

import { composeStories } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStories } from '@storybook/vue3';

import * as FormStories from './LoginForm.stories';

Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/vue/multiple-stories-test.3.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { fireEvent, render, screen } from '@testing-library/vue';

import { composeStories } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStories } from '@storybook/vue3';

import * as FormStories from './LoginForm.stories';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
```js
// tests/Form.test.js

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import * as FormStories from './LoginForm.stories';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
```ts
// tests/Form.test.ts

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import * as FormStories from './LoginForm.stories';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
```js
// tests/Form.test.js

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import Meta, { ValidForm as ValidFormStory } from './LoginForm.stories';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
```ts
// tests/Form.test.ts

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import Meta, { ValidForm as ValidFormStory } from './LoginForm.stories';

Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/vue/reuse-args-test.3.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { render, screen } from '@testing-library/vue';

import { composeStories } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStories } from '@storybook/vue3';

import * as stories from './Button.stories';

Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/vue/reuse-args-test.3.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { render, screen } from '@testing-library/vue';

import { composeStories } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStories } from '@storybook/vue3';

import * as stories from './Button.stories';

Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/vue/single-story-test.3.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { fireEvent, render, screen } from '@testing-library/vue';

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import Meta, { ValidForm as ValidFormStory } from './LoginForm.stories';

Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/vue/single-story-test.3.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { fireEvent, render, screen } from '@testing-library/vue';

import { composeStory } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { composeStory } from '@storybook/vue3';

import Meta, { ValidForm as ValidFormStory } from './LoginForm.stories';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// Storybook's preview file location
import * as globalStorybookConfig from './.storybook/preview';

import { setProjectAnnotations } from '@storybook/testing-vue3';
// Replace @storybook/vue3 with @storybook/testing-vue3 in your tests if you're using the addon
import { setProjectAnnotations } from '@storybook/vue3';

setProjectAnnotations(globalStorybookConfig);
```
10 changes: 5 additions & 5 deletions docs/writing-tests/stories-in-unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
title: 'Unit tests'
---

Teams test a variety of UI characteristics using different tools. Each tool requires you to replicate the same component state over and over. That’s a maintenance headache. Ideally, you’d set up your tests in the same way and reuse that across tools.
Teams test a variety of UI characteristics using different tools. Each tool requires you to replicate the same component state over and over. That’s a maintenance headache. Ideally, you’d set up your tests similarly and reuse that across tools.

Storybook enables you to isolate a component and capture its use cases in a `*.stories.js|ts` file. Stories are standard JavaScript modules cross-compatible with the whole JavaScript ecosystem.
Storybook enables you to isolate a component and capture its use cases in a `*.stories.js|ts` file. Stories are standard JavaScript modules that are cross-compatible with the whole JavaScript ecosystem.

Stories are a practical starting point for UI testing. Import stories into tools like [Jest](https://jestjs.io/), [Testing Library](https://testing-library.com/), [Vitest](https://vitest.dev/) and [Playwright](https://playwright.dev/), to save time and maintenance work.

<IfRenderer renderer='vue'>

## Set up the testing addon

Storybook's [`@storybook/testing-vue3`](https://storybook.js.org/addons/@storybook/testing-vue3/) addon is a powerful tool that simplifies the testing process by allowing you to reuse your stories inside alongside their associated mocks, dependencies, and context, saving time and ensuring consistency and accuracy in the testing process.
By default, Storybook provides a set of APIs that enables you to run your stories as tests with the industry-standard testing tools, simplifying the testing process by allowing you to reuse your stories inside alongside their associated mocks, dependencies, and context. However, if you haven't upgraded to the latest stable Storybook release yet, you'll need to add the [`@storybook/testing-vue3`](https://storybook.js.org/addons/@storybook/testing-vue3/) addon to use these APIs.

Run the following command to install the addon.

Expand All @@ -30,7 +30,7 @@ Run the following command to install the addon.

<Callout variant="info">

If you're using Storybook 7 or higher, the `@storybook/testing-vue3` addon is the only one we support. For Vue 2 users, refer to the [troubleshooting section](#troubleshooting) for additional guidance.
If you're using Storybook 7 or higher, we only provide support for Vue 3 users either natively or via the addon. For Vue 2 users, refer to the [troubleshooting section](#troubleshooting) for additional guidance.

</Callout>

Expand Down Expand Up @@ -94,7 +94,7 @@ Update your test script to include the configuration file:

<IfRenderer renderer='vue'>

Update your test configuration file (e.g., `vite.config.js|ts`) if you're using [Vitest](https://vitest.dev/), or your test script if you're using [Jest](https://jestjs.io/):
Update your test configuration file (e.g., `vite.config.js|ts`) if you're using [Vitest](https://vitest.dev/) or your test script if you're using [Jest](https://jestjs.io/):

<!-- prettier-ignore-start -->

Expand Down
Loading