mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-11 00:06:25 +08:00
23 lines
559 B
Plaintext
23 lines
559 B
Plaintext
```js
|
|
// MyComponent.stories.js|jsx
|
|
|
|
import { userEvent, within } from '@storybook/test';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
export default {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export const ExampleStory = {
|
|
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'));
|
|
},
|
|
};
|
|
```
|