Skip to content

Commit

Permalink
Merge pull request #16938 from 0xR/patch-1
Browse files Browse the repository at this point in the history
Improve the interaction readme
  • Loading branch information
ndelangen authored and shilman committed Jul 26, 2022
1 parent 2f4aeb3 commit 215294e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions addons/interactions/README.md
Expand Up @@ -41,22 +41,25 @@ Interactions relies on "instrumented" versions of Jest and Testing Library, that
`@storybook/testing-library` instead of their original package. You can then use these libraries in your `play` function.

```js
import { Button } from './Button';
import { expect } from '@storybook/jest';
import { within, userEvent } from '@storybook/testing-library';

export default {
title: 'Button',
component: Button,
argTypes: {
onClick: { action: true },
},
};

export const Demo = {
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole('button'));
await expect(args.onClick).toHaveBeenCalled();
},
const Template = (args) => <Button {...args} />;

export const Demo = Template.bind({});
Demo.play = async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole('button'));
await expect(args.onClick).toHaveBeenCalled();
};
```

Expand Down

0 comments on commit 215294e

Please sign in to comment.