mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 02:01:48 +08:00
33 lines
793 B
Plaintext
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' },
|
|
});
|
|
},
|
|
};
|
|
``` |