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

31 lines
765 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.svelte';
<!-- 👇 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'));
}}
render={() => ({
Component: MyComponent,
})} />
<Story
name="FireEventExample"
play={async () => {
await fireEvent.click(screen.getByTestId('data-testid'));
}}
render={() => ({
Component: MyComponent,
})} />
```