unit-test-generator
Generates comprehensive unit tests with AAA pattern (Arrange-Act-Assert), edge cases, error scenarios, and coverage analysis. Creates test files matching…
от patricio0312rev★ 64 звезды на GitHub
Установить unit-test-generator в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Unit Test Generator
Generate comprehensive unit tests with edge cases and AAA pattern.
AAA Pattern Template
// tests/utils/validator.test.ts
import { describe, it, expect } from "vitest";
import { validateEmail } from "@/utils/validator";
describe("validateEmail", () => {
it("should return true for valid email", () => {
// Arrange
const email = "[email protected]";
// Act
const result = validateEmail(email);
// Assert
expect(result).toBe(true);
});
it("should return false for invalid email - missing @", () => {
// Arrange
const email = "userexample.com";
// Act
const result = validateEmail(email);
// Assert
expect(result).toBe(false);
});
it("should return false for invalid email - missing domain", () => {
// Arrange
const email = "user@";
// Act
const result = validateEmail(email);
// Assert
expect(result).toBe(false);
});
});
Comprehensive Test Cases
// src/utils/calculator.ts
export function divide(a: number, b: number): number {
if (b === 0) {
throw new Error("Division by zero");
}
return a / b;
}
// tests/utils/calculator.test.ts
describe("divide", () => {
describe("happy path", () => {
it("should divide positive numbers", () => {
expect(divide(10, 2)).toBe(5);
});
it("should divide negative numbers", () => {
expect(divide(-10, 2)).toBe(-5);
expect(divide(10, -2)).toBe(-5);
expect(divide(-10, -2)).toBe(5);
});
it("should handle decimal results", () => {
expect(divide(10, 3)).toBeCloseTo(3.333, 3);
});
});
describe("edge cases", () => {
it("should handle zero dividend", () => {
expect(divide(0, 5)).toBe(0);
});
it("should handle very large numbers", () => {
expect(divide(Number.MAX_SAFE_INTEGER, 2)).toBe(
Number.MAX_SAFE_INTEGER / 2
);
});
it("should handle very small numbers", () => {
expect(divide(0.0001, 0.0001)).toBe(1);
});
});
describe("error cases", () => {
it("should throw error when dividing by zero", () => {
expect(() => divide(10, 0)).toThrow("Division by zero");
});
it("should throw error when dividing by negative zero", () => {
expect(() => divide(10, -0)).toThrow("Division by zero");
});
});
});
Async Function Testing
// src/services/userService.ts
export async function fetchUser(id: string): Promise<User> {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) {
throw new Error(`User not found: ${id}`);
}
return response.json();
}
// tests/services/userService.test.ts
describe("fetchUser", () => {
beforeEach(() => {
global.fetch = vi.fn();
});
afterEach(() => {
vi.resetAllMocks();
});
it("should fetch user successfully", async () => {
// Arrange
const mockUser = { id: "123", name: "John" };
(global.fetch as any).mockResolvedValueOnce({
ok: true,
json: async () => mockUser,
});
// Act
const user = await fetchUser("123");
// Assert
expect(user).toEqual(mockUser);
expect(global.fetch).toHaveBeenCalledWith("/api/users/123");
});
it("should throw error when user not found", async () => {
// Arrange
(global.fetch as any).mockResolvedValueOnce({
ok: false,
});
// Act & Assert
await expect(fetchUser("999")).rejects.toThrow("User not found: 999");
});
it("should handle network error", async () => {
// Arrange
(global.fetch as any).mockRejectedValueOnce(new Error("Network error"));
// Act & Assert
await expect(fetchUser("123")).rejects.toThrow("Network error");
});
});
Testing Classes
// src/models/ShoppingCart.ts
export class ShoppingCart {
private items: CartItem[] = [];
add(item: CartItem): void {
this.items.push(item);
}
remove(itemId: string): void {
this.items = this.items.filter((i) => i.id !== itemId);
}
getTotal(): number {
return this.items.reduce(
(sum, item) => sum + item.price * item.quantity,
0
);
}
clear(): void {
this.items = [];
}
}
// tests/models/ShoppingCart.test.ts
describe("ShoppingCart", () => {
let cart: ShoppingCart;
beforeEach(() => {
cart = new ShoppingCart();
});
describe("add", () => {
it("should add item to cart", () => {
// Arrange
const item = { id: "1", name: "Product", price: 10, quantity: 1 };
// Act
cart.add(item);
// Assert
expect(cart.getTotal()).toBe(10);
});
it("should add multiple items", () => {
// Arrange
const item1 = { id: "1", name: "Product 1", price: 10, quantity: 1 };
const item2 = { id: "2", name: "Product 2", price: 20, quantity: 2 };
// Act
cart.add(item1);
cart.add(item2);
// Assert
expect(cart.getTotal()).toBe(50); // 10 + (20 * 2)
});
});
describe("remove", () => {
it(
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл unit-test-generator?
Generates comprehensive unit tests with AAA pattern (Arrange-Act-Assert), edge cases, error scenarios, and coverage analysis. Creates test files matching source structure with complete test suites. Use for "unit testing", "test generation", "Jest tests", or "test coverage".
Как установить скилл unit-test-generator?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unit-test-generator запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…