Skip to content

Commit

Permalink
migrate tests to use Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleSeo committed Dec 11, 2024
1 parent 7723605 commit 3c86d1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "eslint .",
"test": "vitest",
"preview": "vite preview",
"sb": "storybook dev -p 6006",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"prepare": "panda codegen"
Expand Down
14 changes: 13 additions & 1 deletion src/components/Button/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { expect, fn, userEvent } from "@storybook/test";
import { Button } from "./Button";

const meta = {
Expand All @@ -19,6 +19,18 @@ export const Basic: Story = {
type: "button",
children: "Click",
},
play: async ({ args: { onClick }, canvas, step }) => {
const button = canvas.getByRole("button");

await step("renders a button with text", async () => {
expect(button).toHaveTextContent("Click");
});

await step("calls onClick handler when clicked", async () => {
await userEvent.click(button);
expect(onClick).toHaveBeenCalledTimes(1);
});
},
};

export const Submit: Story = {
Expand Down
23 changes: 0 additions & 23 deletions src/components/Button/Button.test.tsx

This file was deleted.

0 comments on commit 3c86d1c

Please sign in to comment.