Skip to content

Commit

Permalink
migrate tests to use Storybook
Browse files Browse the repository at this point in the history
DaleSeo committed Dec 11, 2024
1 parent 9219cf8 commit 01a6f07
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
@@ -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"
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 = {
@@ -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 = {
23 changes: 0 additions & 23 deletions src/components/Button/Button.test.tsx

This file was deleted.

0 comments on commit 01a6f07

Please sign in to comment.