The /test command generates tests, runs existing tests, or checks test coverage. It applies the testing-patterns skill to create comprehensive test suites.
Sub-commands
/test # Run all tests
/test [file/feature] # Generate tests for specific target
/test coverage # Show test coverage report
/test watch # Run tests in watch mode
When to use this
After features Verify new features work correctly
Before deployment Ensure everything passes before shipping
Bug prevention Add tests to prevent regression
CI/CD pipelines Automate quality checks
How it works
Generate tests
When you test a file or feature:
Analyze the code
Identify functions and methods
Find edge cases
Detect dependencies to mock
Generate test cases
Happy path tests
Error cases
Edge cases
Integration tests (if needed)
Write tests
Use project’s test framework (Jest, Vitest, etc.)
Follow existing test patterns
Mock external dependencies
For test generation
You’ll receive:
Test Plan
Test Case Type Coverage Should create user Unit Happy path Should reject invalid email Unit Validation Should handle db error Unit Error case
Generated Tests
Complete test file with:
Describe blocks
Test cases
Mocks and fixtures
Assertions
Run with: npm test
For test execution
🧪 Running tests...
✅ auth.test.ts (5 passed)
✅ user.test.ts (8 passed)
❌ order.test.ts (2 passed, 1 failed)
Failed:
✗ should calculate total with discount
Expected: 90
Received: 100
Total: 15 tests (14 passed, 1 failed)
Test patterns
All generated tests follow the AAA pattern (Arrange-Act-Assert):
describe ( 'AuthService' , () => {
describe ( 'login' , () => {
it ( 'should return token for valid credentials' , async () => {
// Arrange
const credentials = {
email: '[email protected] ' ,
password: 'pass123'
};
// Act
const result = await authService . login ( credentials );
// Assert
expect ( result . token ). toBeDefined ();
});
it ( 'should throw for invalid password' , async () => {
// Arrange
const credentials = {
email: '[email protected] ' ,
password: 'wrong'
};
// Act & Assert
await expect (
authService . login ( credentials )
). rejects . toThrow ( 'Invalid credentials' );
});
});
});
Usage examples
/test src/services/auth.service.ts
Generate tests for authentication service
/test user registration flow
Test the complete user signup process
Show which code is covered by tests
Analyze and fix failing tests
Key principles
Test behavior not implementation : Focus on what the code does, not how it does it.
One assertion per test : When practical, each test should verify one specific behavior.
Descriptive test names : Test names should clearly state what is being tested.
Mock external dependencies : Isolate the code under test by mocking APIs, databases, etc.
/debug - Use tests to verify fixes
/deploy - Tests run automatically before deployment