Agent skill
jest
Use when implementing or expanding ESLint rule test suites.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/jest-blumintinc-eslint-custom-rules
SKILL.md
Given an ESLint rule implementation (e.g., src/rules/my-rule.ts), implement or update a comprehensive Jest test suite in src/tests/ (e.g., src/tests/my-rule.test.ts). The suite must achieve high code coverage (90% minimum, 100% preferred) and pass all checks.
Purpose
Ensure every rule ships with a thorough, repeatable test suite that prevents false positives, catches regressions, and documents expected behavior.
Why the System Was Built
Reliable rule tests keep 100+ custom rules stable across refactors and TypeScript upgrades by codifying expected diagnostics, auto-fixes, and edge cases.
Definitions
- RuleTester: Harness that runs lint cases against a rule and asserts reported errors/fixes.
- Valid case: Code that must NOT trigger the rule (guards against false positives).
- Invalid case: Code that MUST trigger the rule with expected
messageId(prevents false negatives and verifies fixes). - Coverage target: 90% minimum, 100% preferred across rule logic and fixers.
Core Components
ruleTesterTs,ruleTesterJsx,ruleTesterJsonfromsrc/utils/ruleTester.tsfor TS, JSX/React, and JSON rules.- Jest with
ts-jestfor executing suites. - Auto-fix assertions via
outputin invalid cases when the rule is fixable.
Directory Structure
- Tests live in
src/tests/, mirroring rule filenames (src/rules/foo.ts→src/tests/foo.test.ts). - RuleTester utilities:
src/utils/ruleTester.ts. - Coverage output:
coverage/.
Setup and Execution
- Run all tests:
npm test - Run a single suite:
npx jest src/tests/<rule>.test.ts
Test Case Patterns
import { ruleTesterTs, ruleTesterJsx, ruleTesterJson } from '../utils/ruleTester';
import { myRule } from '../rules/my-rule';
// TypeScript rules
ruleTesterTs.run('my-rule', myRule, { valid: [], invalid: [] });
// React/JSX rules
ruleTesterJsx.run('my-rule', myRule, { valid: [], invalid: [] });
// JSON rules
ruleTesterJson.run('my-rule', myRule, { valid: [], invalid: [] });
✅ Valid Cases (false-positive prevention)
- Good patterns that must NOT report.
- Include similar-but-correct code and ignored paths.
valid: [
'const x = 1;',
{ code: 'const x = 1;', filename: 'src/utils/math.ts', options: [{ allow: true }] },
]
❌ Invalid Cases (false-negative prevention)
- Violations that MUST report with the right
messageId. - Provide
outputwhen verifying auto-fix.
invalid: [
{
code: 'const x = var;',
errors: [{ messageId: 'unexpectedVar' }],
output: 'const x = fixedVar;',
},
]
Usage Instructions
- Analyze the rule (targets, visitors, edge cases).
- Select the correct tester variant.
- Draft cases: 10+ valid and 10+ invalid, covering nested and tricky syntax.
- Run
npx jest src/tests/<rule>.test.ts. - Refine until coverage ≥90% and all assertions pass.
- Keep fixes minimal and focused on requested behavior.
How It Makes Developers' Lives Easier
- Prevents regressions when refactoring rules or upgrading TypeScript/ESLint.
- Documents expected diagnostics and fixes for future contributors.
- Speeds debugging by localizing failures to a single rule suite.
Critical Insights for Maintainers
- Test the intent:
messageIdshould match the rule's purpose. - Use filenames when rule behavior depends on file type/path.
- Always assert
outputfor fixable rules to guard against unsafe fixes.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?