storybook/docs/snippets/react/my-component-play-function-with-selectevent.js.mdx
2021-10-05 02:08:12 +01:00

33 lines
913 B
Plaintext

```js
// MyComponent.js | MyComponent.jsx | MyComponent.ts | MyComponent.tsx
// These are placeholders until the addon-interaction is out
import { screen, fireEvent } from '@testing-library/react';
import { MyComponent } from './MyComponent';
export default {
component: MyComponent,
};
// This is a placeholder mocked sleep function to be updated once the addon-interactions is out.
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export const ExampleChangeEvent = {
play: async () => {
await fireEvent.change(screen.getByTestId('select'), {
target: { value: 'One Item' },
});
await sleep(2000);
await fireEvent.change(screen.getByTestId('select'), {
target: { value: 'Another Item' },
});
await sleep(2000);
await fireEvent.change(screen.getByTestId('select'), {
target: { value: 'Yet another item' },
});
},
};
```