storybook/docs/snippets/vue/my-component-play-function-with-selectevent.mdx.mdx
2022-07-07 18:50:21 +01:00

42 lines
1.0 KiB
Plaintext

```md
<!-- MyComponent.stories.mdx -->
import { Meta, Story } from '@storybook/addon-docs';
import { userEvent, screen } from '@storybook/testing-library';
import MyComponent from './MyComponent.vue';
<Meta title="ExampleChangeEvent" component={MyComponent} />
<!-- Function to emulate pausing between interactions -->
export const sleep= (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
<!--
👇 Render functions are a framework specific feature to allow you control on how the component renders.
See https://storybook.js.org/docs/7.0/vue/api/csf
to learn how to use render functions.
-->
<Story
name="ExampleChangeEvent"
play={async () => {
const select = screen.getByRole('listbox');
await userEvent.selectOptions(select, ['One Item']);
await sleep(2000);
await userEvent.selectOptions(select, ['Another Item']);
await sleep(2000);
await userEvent.selectOptions(select, ['Yet another item']);
}}
render={()=>({
components: { MyComponent },
template: '<MyComponent/>',
})} />
```