Skip to content

Commit 331177b

Browse files
Merge pull request #32664 from storybookjs/docs_main_config_features_add_experimentaltestsyntax
Docs: Add experimental test syntax to main config features page
2 parents c2829a1 + bef844b commit 331177b

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```ts filename=".storybook/main.js|ts (CSF Next 🧪)" renderer="react" language="ts"
2+
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
3+
import { defineMain } from '@storybook/your-framework/node';
4+
5+
export default defineMain({
6+
framework: '@storybook/your-framework',
7+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
8+
features: {
9+
experimentalTestSyntax: true,
10+
},
11+
});
12+
```

docs/api/csf/csf-next.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,27 @@ export const PrimaryDisabled = Primary.extend({
224224
});
225225
```
226226

227+
#### `<Story>.test`
228+
229+
(⚠️ **Experimental**)
230+
231+
A more ergonomic way to define [tests for your stories](../../writing-tests/index.mdx). While this API is still experimental, it is [documented in the RFC to gather feedback](https://github.com/storybookjs/storybook/discussions/30119) and must be enabled via the [`experimentalTestSyntax` feature flag](../main-config/main-config-features.mdx#experimentaltestsyntax).
232+
233+
```ts title="Button.stories.js|ts"
234+
// ...from above
235+
export const PrimaryDisabled = Primary.extend({ args: { disabled: true } });
236+
237+
// 👇 .test method: Attach tests to a story
238+
// The test function can run the same code as the play function
239+
PrimaryDisabled.test('should be disabled', async ({ canvas, userEvent, args }) => {
240+
const button = await canvas.findByRole('button');
241+
await userEvent(button).click();
242+
243+
await expect(button).toBeDisabled();
244+
await expect(args.onClick).not.toHaveBeenCalled();
245+
});
246+
```
247+
227248
## Upgrade to CSF Next
228249

229250
You can upgrade your stories to CSF Next either automatically (from CSF 3) or manually (from CSF 1, 2, or 3). CSF Next is designed to be usable incrementally; you do not have to upgrade all of your story files at once. However, you cannot mix story formats within the same file.

docs/api/main-config/main-config-features.mdx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@ Parent: [main.js|ts configuration](./main-config.mdx)
99

1010
Type:
1111

12+
<If renderer="react">
13+
14+
```ts
15+
{
16+
actions?: boolean;
17+
argTypeTargetsV7?: boolean;
18+
backgrounds?: boolean;
19+
controls?: boolean;
20+
developmentModeForBuild?: boolean;
21+
experimentalTestSyntax?: boolean;
22+
highlight?: boolean;
23+
interactions?: boolean;
24+
legacyDecoratorFileOrder?: boolean;
25+
measure?: boolean;
26+
outline?: boolean;
27+
toolbars?: boolean;
28+
viewport?: boolean;
29+
}
30+
```
31+
</If>
32+
33+
<If renderer="angular">
34+
1235
```ts
1336
{
1437
actions?: boolean;
@@ -26,6 +49,28 @@ Type:
2649
viewport?: boolean;
2750
}
2851
```
52+
</If>
53+
54+
<If notRenderer={['react','angular']}>
55+
56+
```ts
57+
{
58+
actions?: boolean;
59+
argTypeTargetsV7?: boolean;
60+
backgrounds?: boolean;
61+
controls?: boolean;
62+
developmentModeForBuild?: boolean;
63+
highlight?: boolean;
64+
interactions?: boolean;
65+
legacyDecoratorFileOrder?: boolean;
66+
measure?: boolean;
67+
outline?: boolean;
68+
toolbars?: boolean;
69+
viewport?: boolean;
70+
}
71+
```
72+
</If>
73+
2974

3075
Enables Storybook's additional features.
3176

@@ -35,12 +80,16 @@ Type: `boolean`
3580

3681
Enable the [Actions](../../essentials/actions.mdx) feature.
3782

83+
<If renderer="angular">
84+
3885
## `angularFilterNonInputControls`
3986

4087
Type: `boolean`
4188

4289
Filter non-input controls in Angular.
4390

91+
</If>
92+
4493
## `argTypeTargetsV7`
4594

4695
(⚠️ **Experimental**)
@@ -79,6 +128,24 @@ Set `NODE_ENV` to `'development'` in built Storybooks for better testing and deb
79128

80129
{/* prettier-ignore-end */}
81130

131+
<If renderer="react">
132+
133+
## `experimentalTestSyntax`
134+
135+
(⚠️ **Experimental**)
136+
137+
Type: `boolean`
138+
139+
Enable the [experimental `.test` method with the CSF Next format](../csf/csf-next#storytest).
140+
141+
{/* prettier-ignore-start */}
142+
143+
<CodeSnippets path="main-config-features-experimental-test-syntax.md" />
144+
145+
{/* prettier-ignore-end */}
146+
147+
</If>
148+
82149
## `highlight`
83150

84151
Type: `boolean`

0 commit comments

Comments
 (0)