storybook/docs/snippets/common/my-component-play-function-with-canvas.js.mdx
2024-02-29 14:30:28 +00:00

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'));
},
};
```