storybook/docs/snippets/common/my-component-play-function-with-canvas.js.mdx
Kyle Gach b97d94e005 Address feedback
- Newline following filename comment
- Fix URLs in comments
- Ensure consistent usage of `ts` vs `tsx` language
2023-01-12 14:17:39 -07:00

24 lines
611 B
Plaintext

```js
// MyComponent.stories.js|jsx
import { getByRole, userEvent, within } from '@storybook/testing-library';
import { MyComponent } from './MyComponent';
export default {
title: 'WithCanvasElement',
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'));
},
};
```