Loading...
Loading...
Compare original and translation side by side
# 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 test# 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-dompackage.jsontest{ "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()expectawaitresolvesrejectstest()it()expectawaitresolvesrejects