component-testing
Use this skill to create or modify tests for a component.
When & Why to Use This Skill
This Claude skill streamlines the frontend development workflow by automating the creation and modification of component tests and Storybook stories. It ensures UI components are robust and well-documented by generating standardized test files, verifying event handling logic, and visualizing various component states, ultimately improving code quality and reducing manual testing effort.
Use Cases
- Automated Storybook Generation: Quickly create '.stories.tsx' files for new UI components to visualize and document different states such as loading, error, and success.
- Regression Testing for UI: Modify existing component tests when UI logic or styling changes to ensure stability and prevent visual or functional regressions.
- Event Handling Verification: Generate specific test cases to verify complex event handling and user interaction logic within interactive components like buttons, forms, and inputs.
- Standardizing Test Suites: Enforce project-wide consistency by using predefined templates for component stories, ensuring all tests follow the same naming conventions and structural patterns.
name: component-testing description: Use this skill to create or modify tests for a component.
Component testing
Use this skill to create or modify component tests for the application.
Creating stories
- Create a separate story for each state of the component.
- Add tests to verify event handling logic included in the component.
- Stories must be added next to the component.
- If the component file is
button.tsxthen the stories file isbutton.stories.tsx
Template for a component story
import { GitHubSignInButton } from "./github-signin-button"; // The module exporting the component
import { Meta, StoryObj } from "@storybook/nextjs-vite"; // Required framework components
const meta = {
component: GitHubSignInButton, // The exported component
title: "Components/Auth/GitHubSignInButton", // The logical path to the component.
}
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {},
};