storybook/docs/snippets/react/my-component-play-function-with-clickevent.mdx.mdx
2021-10-14 23:00:26 +01:00

25 lines
655 B
Plaintext

```md
<!-- MyComponent.stories.mdx -->
import { Meta, Story } from '@storybook/addon-docs';
import { fireEvent, screen, userEvent } from '@storybook/testing-library';
import { MyComponent } from './MyComponent.js';
<!-- 👇 Marking the onClick with this configuration will log the event in the Actions panel -->
<Meta title="ClickExamples" component={MyComponent} argTypes={{ onClick: { action: true }}/>
<Story
name="ClickExample"
play={async () => {
await userEvent.click(screen.getByRole('button'));
}} />
<Story
name="FireEventExample"
play={async () => {
await fireEvent.click(screen.getByTestId('data-testid'));
}} />
```