Testing Standards Skill
Test Structure (AAA Pattern)
describe('Component/Function Name', () => {
it('should do something specific', () => {
// Arrange - Set up test data
const input = { foo: 'bar' }
// Act - Execute the code
const result = functionUnderTest(input)
// Assert - Verify results
expect(result).toEqual(expectedOutput)
})
})
Test Categories
Unit Tests
- Test single functions/methods
- Mock all dependencies
- Fast (<100ms per test)
- High coverage (80%+)
Integration Tests
- Test component interactions
- Use test database
- Moderate speed
- Focus on critical paths
E2E Tests
- Test complete user flows
- Use real browser
- Slower execution
- Test happy paths only
Best Practices
- Descriptive Names:
it('should return 401 when token is expired') - One Assert Per Concept: Test one thing at a time
- Independent Tests: No shared state between tests
- Use Factories: Create test data with factories
- Mock External Services: APIs, databases, file system
Converted and distributed by TomeVault — claim your Tome and manage your conversions.