storybook/docs/snippets/common/my-component-play-function-with-delay.js.mdx
2023-11-28 10:58:12 +01:00

33 lines
896 B
Plaintext

```js
// MyComponent.stories.js|jsx
import { userEvent, within } from '@storybook/test';
import { MyComponent } from './MyComponent';
export default {
component: MyComponent,
};
/* 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 DelayedStory = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const exampleElement = canvas.getByLabelText('example-element');
// The delay option sets the amount of milliseconds between characters being typed
await userEvent.type(exampleElement, 'random string', {
delay: 100,
});
const AnotherExampleElement = canvas.getByLabelText('another-example-element');
await userEvent.type(AnotherExampleElement, 'another random string', {
delay: 100,
});
},
};
```