Skip to main content
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:
1

Analyze the code

  • Identify functions and methods
  • Find edge cases
  • Detect dependencies to mock
2

Generate test cases

  • Happy path tests
  • Error cases
  • Edge cases
  • Integration tests (if needed)
3

Write tests

  • Use project’s test framework (Jest, Vitest, etc.)
  • Follow existing test patterns
  • Mock external dependencies

Output format

For test generation

You’ll receive: Test Plan
Test CaseTypeCoverage
Should create userUnitHappy path
Should reject invalid emailUnitValidation
Should handle db errorUnitError 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
/test coverage
Show which code is covered by tests
/test fix failed 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

Build docs developers (and LLMs) love