Loading...
Loading...
Add test coverage to existing code with correct mock patterns. Use when adding tests to untested modules, writing regression tests for bugs, or user asks to test a specific file. Handles mockReset:true, vi.hoisted(), forwarding pattern, and test app builder utilities.
npx skill4agent add acedergren/agentic-tools write-tests*.test.ts| Module Type | Strategy |
|---|---|
| Route handler | Test app builder + session simulation + |
| Repository | Mock DB connection + counter-based |
| Framework plugin | Real framework instance + selective dependency mocks |
| Pure utility | No mocks — test inputs/outputs directly |
| Service w/ DI | Mock injected deps via forwarding pattern |
mockReset: trueconst { mockFn } = vi.hoisted(() => ({
mockFn: vi.fn(),
}));
vi.mock("./dependency", () => ({
dependency: (...args: unknown[]) => mockFn(...args),
}));
beforeEach(() => {
// MUST reconfigure here — mockReset clears return values between tests
mockFn.mockResolvedValue(defaultResult);
});mockResolvedValueOncemockResetmockImplementationvi.mock()vi.hoisted()vi.importActual()npx vitest run <test-file> --reporter=verbose$ARGUMENTS/write-tests src/routes/admin/settings.ts