mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 07:01:53 +08:00
- Newline following filename comment - Fix URLs in comments - Ensure consistent usage of `ts` vs `tsx` language
30 lines
820 B
Plaintext
30 lines
820 B
Plaintext
```ts
|
|
// MyComponent.stories.ts|tsx
|
|
|
|
import { userEvent, within } from '@storybook/testing-library';
|
|
|
|
// Replace your-framework with the name of your framework
|
|
import type { Meta, StoryObj } from '@storybook/your-framework';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
const meta: Meta<typeof MyComponent> = {
|
|
title: 'WithCanvasElement',
|
|
component: MyComponent,
|
|
};
|
|
export default meta;
|
|
|
|
type Story = StoryObj<typeof MyComponent>;
|
|
|
|
export const ExampleStory: Story = {
|
|
play: async ({ canvasElement }) => {
|
|
// Assigns canvas to the component root element
|
|
const canvas = within(canvasElement);
|
|
|
|
// Starts querying from the component's root element
|
|
await userEvent.type(canvas.getByTestId('example-element'), 'something');
|
|
await userEvent.click(canvas.getByRole('another-element'));
|
|
},
|
|
};
|
|
```
|