/dev-tools:writing-tests-typescriptfrom dev-tools
Instructions for writing TypeScript tests (Jest), including typed mocks and testing patterns.
Ships in dev-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
If this plugin is not initialized or an Agent IX command fails, read the dev-tools setup guide for its prerequisites and local diagnosis.
This skill provides guidelines and patterns for writing TypeScript tests using jest, compliant with the Agent-IX Golden Path.
Source Spec: Derived from typescript-lib-cookiecutter and nodejs-lib patterns.
jest.tests/ directory or alongside source files as *.test.ts or *.spec.ts.describe blocks and test/it functions.prettier and eslint rules.Trace: line in its
JSDoc (or a // Trace: comment) listing the criterion ids, comma separated
(Trace: FR-001-AC-2, FR-001-AC-3). quire matrix computes the Test Matrix from these
tags; ids in Description or Criteria bind nothing. Do not add rows to spec/tests.md.import { sum } from '../src/math';
/**
* Tests for the Math module functions.
*/
describe('Math module', () => {
/**
* Description:
* Verifies that the sum function correctly adds two numbers.
*
* Assumptions:
* - Inputs are numbers
*
* Criteria:
* - Result is the arithmetic sum of inputs
*
* Trace: FR-001-AC-1
*/
it('adds two numbers correctly', () => {
expect(sum(1, 2)).toBe(3);
});
});
Use jest.mock for module mocking. Use jest.spyOn for method spying.
import { performAction } from '../src/action';
import { api } from '../src/api';
jest.mock('../src/api');
/**
* Tests for the Action module.
*/
describe('Action', () => {
/**
* Description:
* Verifies that performAction makes a POST request to the API.
*
* Assumptions:
* - api.post is a jest mock
*
* Criteria:
* - api.post is called exactly once
*/
it('calls the api', async () => {
(api.post as jest.Mock).mockResolvedValue({ data: 'ok' });
await performAction();
expect(api.post).toHaveBeenCalled();
});
});
Use jest.Mocked<T> for better type safety.
import { api } from '../src/api';
jest.mock('../src/api');
const mockedApi = api as jest.Mocked<typeof api>;
// usage
mockedApi.post.mockResolvedValue(...)
Always await promises.
/**
* Description:
* Verifies that data is fetched successfully.
*
* Assumptions:
* - fetchData resolves with data
*
* Criteria:
* - Returned data is defined
*/
it('fetches data', async () => {
const data = await fetchData();
expect(data).toBeDefined();
});
Use beforeAll, afterAll, beforeEach, afterEach for managing test lifecycle.
beforeEach(() => {
jest.clearAllMocks();
});
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub agent-ix/dev-tools --plugin dev-tools15 skills in this plugin
/audit-commentsAudit comments in a repository or bounded code section, remove tautologies and stale notes, convert decision records to ADRs, file issues for hack-enabling excuses, and add a ratcheting lint rule. Use when asked to audit or delete code comments./backport-codeA skill for systematically backporting bug fixes and features across specs, templates, and downstream repositories./code-reviewReview code for Agent-IX Golden Path compliance, focusing on test style, mock boundaries, implementation gaps, and code-test alignment. Dispatches by language — Python inline, Rust via `rust-review`, React via `review-react`.Other plugins' skills for the same job