- Home
- Skills
- Kyzooghost
- Skills
- Unit Test
unit-test_skill
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill kyzooghost/skills --skill unit-test- SKILL.md3.5 KB
Overview
This skill provides concise guidelines for writing and reviewing unit tests focused on clarity, determinism, and reviewer responsibilities. It codifies the AAA pattern, meaningful naming, mocking strategies, and anti-patterns to prevent flaky or brittle tests. Use it to raise the quality and trustworthiness of test suites when adding, changing, or reviewing *.test.* files.
How this skill works
The skill inspects test code for structure and practices: it verifies Arrange-Act-Assert organization, checks that each test targets a single behavior, and flags weak assertions or reliance on global state. It looks for determinism controls like time/randomness mocking and warns about testing implementation details. For PR reviews, it guides reviewers on validating that tests fail when the system under test is broken and on choosing correct matchers.
When to use it
- When writing new unit tests for any module or component
- When reviewing PRs that add or modify *.test.* files
- When refactoring tests to improve clarity, isolation, or coverage
- When diagnosing flaky tests or intermittent CI failures
- When establishing or enforcing team testing conventions
Best practices
- Follow AAA (Arrange, Act, Assert) in every test for readability
- Give tests meaningful names that describe expected behavior, not implementation
- Test one behavior per test and isolate tests from each other
- Mock time, randomness, and external systems to ensure determinism
- Use precise matchers; avoid weak assertions like toBeTruthy or toBeDefined
Example use cases
- Adding unit tests for a new utility function and ensuring names describe outcomes
- Reviewing a test PR and rejecting tests that rely on real time or global state
- Refactoring a brittle test suite by introducing jest.useFakeTimers and deterministic mocks
- Validating that a failing code change also causes related tests to fail (test the test)
- Replacing weak matchers with explicit assertions to increase test signal
FAQ
Mock external dependencies that introduce nondeterminism or slow tests (network, timers, randomness). Keep mocks focused on public behavior and avoid mocking internal implementation.
What if a single behavior requires multiple assertions?
Multiple related assertions are acceptable if they verify one observable behavior. If assertions cover distinct behaviors, split them into separate tests.