Skip to content

Instantly share code, notes, and snippets.

@tidusia
Last active November 30, 2023 13:28
Show Gist options
  • Save tidusia/4d116f9a66b0c51beecdf8f482f1bebc to your computer and use it in GitHub Desktop.
Save tidusia/4d116f9a66b0c51beecdf8f482f1bebc to your computer and use it in GitHub Desktop.
import { Meta, StoryObj } from "@storybook/react";
import Button from ".";
import { userEvent, within, waitFor } from "@storybook/testing-library";
import { expect } from "@storybook/jest";
export default {
component: Button,
argTypes: {
onClick: { action: true },
},
parameters: {
layout: "centered",
},
} as Meta<typeof Button>;
export const Default: StoryObj<typeof Button> = {
args: {
content: "Click me",
},
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
const user = userEvent.setup({ delay: 50 });
await user.click(canvas.getByText("Click me"));
await waitFor(() => expect(args.onClick).toHaveBeenCalledTimes(1));
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment