Loading...
Loading...
Analyze existing code and write comprehensive unit and integration tests for it. Detects the test framework, identifies untested code paths, and generates tests with proper mocking, edge cases, and assertions. Use when the user asks to add tests, improve coverage, or test a specific module.
npx skill4agent add spencerpauly/awesome-cursor-skills writing-tests# Check package.json for test runner
cat package.json | grep -E "jest|vitest|mocha|playwright|cypress"vitest.config.tsjest.config.tsplaywright.config.ts.mocharc.*npm install -D vitest @testing-library/react @testing-library/jest-domtestpackage.json{ "test": "vitest run", "test:watch": "vitest" }__tests__/src/utils/format.tssrc/utils/format.test.tssrc/components/Button.tsxsrc/components/Button.test.tsximport { describe, it, expect, vi } from "vitest";
describe("functionName", () => {
// Happy path
it("returns formatted output for valid input", () => { ... });
// Edge cases
it("handles empty string", () => { ... });
it("handles null/undefined input", () => { ... });
// Error cases
it("throws on invalid argument", () => { ... });
// Boundary conditions
it("handles maximum length input", () => { ... });
});vi.mock("@/lib/db", () => ({
query: vi.fn().mockResolvedValue([{ id: 1, name: "test" }]),
}));vi.mock("@/hooks/useUser", () => ({
useUser: () => ({ user: { name: "Test" }, isLoading: false }),
}));import { render, screen, fireEvent } from "@testing-library/react";
it("renders the button and handles click", () => {
const onClick = vi.fn();
render(<Button onClick={onClick}>Click me</Button>);
fireEvent.click(screen.getByRole("button", { name: "Click me" }));
expect(onClick).toHaveBeenCalledOnce();
});npm testtest()it()expectawaitresolvesrejects