storybook/docs/snippets/web-components/storybook-interactions-step-function.js.mdx
2023-11-28 10:58:12 +01:00

29 lines
759 B
Plaintext

```js
// MyComponent.stories.js
import { userEvent, within } from '@storybook/test';
export default = {
component: 'my-component',
};
/*
* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const Submitted = {
play: async ({ args, canvasElement, step }) => {
const canvas = within(canvasElement);
await step('Enter email and password', async () => {
await userEvent.type(canvas.getByTestId('email'), 'hi@example.com');
await userEvent.type(canvas.getByTestId('password'), 'supersecret');
});
await step('Submit form', async () => {
await userEvent.click(canvas.getByRole('button'));
});
},
};
```