Agent skill
Write Unit Tests
Write Jest unit tests following project conventions with proper stubs and assertions.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/unit-test-carrot-foundation-methodology-rules
SKILL.md
-
File naming: Use
*.spec.tsfor unit tests and*.e2e.spec.tsfor end-to-end tests. Place test files alongside the source file they test. -
Test framework: Use Jest with ts-jest. Test environment variables are loaded from
.env-files/.env.test. -
Test data generation:
- Use
@faker-js/fakerfor random synthetic data (names, dates, numbers) - Use
zockerwithcreateStubFromSchema()for generating data from Zod schemas - Import shared test helpers from
@carrot-fndn/shared/testing:stubRuleInput(),stubDocument(),createStubFromSchema() - NEVER use real data (company names, tax IDs, license plates, addresses, PII)
- Use
-
Test structure:
- Use
describeblocks to group related tests - Use
it.eachfor table-driven tests when testing multiple similar scenarios - Use
expect.objectContaining()for partial assertions on objects - Keep test descriptions clear and descriptive using
shouldlanguage
- Use
-
Rule processor tests: Follow the standard pattern:
{rule-name}/ ├── {rule-name}.processor.spec.ts # Unit tests for evaluateResult() ├── {rule-name}.lambda.e2e.spec.ts # E2E tests for the Lambda handler └── {rule-name}.test-cases.ts # Shared test data and fixtures -
Assertions:
- Test both success and failure paths
- Verify error messages and types, not just that errors are thrown
- For rule processors, test that
evaluateResult()returns the expectedRuleOutput
-
Run and verify: Execute
pnpm nx test <project-name>to run tests for the specific project. Ensure all tests pass before finishing.
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?