storybook/docs/snippets/angular/my-component-play-function-with-selectevent.ts.mdx
2021-10-14 17:15:03 +01:00

33 lines
793 B
Plaintext

```ts
// MyComponent.stories.ts
import { fireEvent, screen } from '@storybook/testing-library';
import { MyComponent } from './MyComponent.component';
export default {
component: MyComponent,
};
// Custom function to emulate a pause
function sleep(ms: any) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// Queries the element by it's role and fires the event
export const ExampleChangeEvent = {
play: async () => {
const dropdown = screen.getByRole('listbox');
await fireEvent.change(dropdown, { target: { value: 'One Item'} });
await sleep(2000);
await fireEvent.change(dropdown, { target: { value: 'Another Item' } });
await sleep(2000);
await fireEvent.change(dropdown, {
target: { value: 'Yet another item' },
});
},
};
```