Monitor Test Validator
Powerful hook for automatically, relevant, tests, after. Includes structured workflows, validation checks, and reusable patterns for testing.
Monitor Test Validator
Validates test suites and monitoring configurations after test execution, ensuring tests remain reliable and monitoring coverage stays comprehensive.
When to Use This Hook
Attach this hook when you need to:
- Verify that test suites maintain minimum coverage thresholds after code changes
- Validate that monitoring rules have corresponding test coverage
- Detect flaky tests, missing assertions, and incomplete test setups automatically
Consider alternatives when:
- Your CI system already runs comprehensive test validation and reporting
- You prefer to validate tests only at commit or push time, not after every edit
Quick Start
Configuration
name: monitor-test-validator type: hook trigger: PostToolUse category: testing
Example Trigger
# Hook triggers after test files are edited claude> Edit src/__tests__/userService.test.ts # Validator checks the test file for quality issues
Example Output
Test Validator: Analyzing src/__tests__/userService.test.ts
Assertions per test: avg 2.4 (min: 1) ........... PASS
Empty test blocks: 0 ............................ PASS
Skipped tests (.skip): 1 ........................ WARN
Console.log in tests: 0 ......................... PASS
Missing afterEach cleanup: detected .............. WARN
Validation complete: 2 warnings
Core Concepts
Validation Checks Overview
| Aspect | Details |
|---|---|
| Assertion Count | Ensures each test has at least one assertion |
| Empty Tests | Detects it() blocks with no body or only comments |
| Skipped Tests | Warns on .skip or xit that may be forgotten |
| Cleanup Verification | Checks for missing afterEach/tearDown in tests with setup |
| Console Statements | Flags console.log left in test files from debugging |
Validation Workflow
Test File Modified
|
Parse Test Blocks
|
┌────┼────┬────┐
| | | |
Assert Empty Skip Cleanup
Count Tests Check Check
| | | |
└────┼────┴────┘
|
Score Quality
|
┌────┴────┐
| |
Pass Warnings
| |
Done Report
Issues
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
min_assertions | number | 1 | Minimum assertions required per test block |
warn_on_skip | boolean | true | Warn when .skip or xit tests are found |
check_cleanup | boolean | true | Verify cleanup hooks exist when setup hooks are present |
max_test_lines | number | 50 | Warn on excessively long individual test blocks |
file_patterns | string[] | ["*.test.*","*.spec.*","test_*.*"] | File patterns to validate |
Best Practices
-
Require Meaningful Assertions - A test with zero assertions always passes but tests nothing. Set
min_assertionsto at least 1 and encourage multiple assertions per test for thorough verification. -
Track Skipped Tests - Skipped tests tend to stay skipped forever. The warning reminds the team to either fix and re-enable them or delete them if they are no longer relevant.
-
Enforce Cleanup Patterns - Tests with
beforeEachsetup but noafterEachcleanup can leak state between tests, causing intermittent failures. The validator catches this mismatch. -
Set Test Size Limits - Individual test blocks over 50 lines are hard to understand and maintain. The validator encourages breaking large tests into smaller, focused tests.
-
Run on Test Files Only - The validator should only trigger when test files are edited, not production code. Use specific file patterns to avoid unnecessary validation runs.
Common Issues
-
Custom Assertion Libraries - If your project uses a custom assertion library instead of
expect(), the validator may not recognize assertions. Add custom assertion function names to the detection patterns. -
Dynamic Test Generation - Tests generated by loops or
test.eachmay appear to have fewer assertions than they actually do. Add support for table-driven test patterns. -
False Positives on Utility Files - Test utility files (
testHelpers.ts,fixtures.ts) may match test file patterns but do not contain test blocks. Add these to an exclusion list.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.