All new functionality must include corresponding unit tests. This is especially critical for utility functions, core logic modules, stream processing, data transformation methods, and complex business logic. Without unit tests, code becomes difficult to understand and maintain over time.
Key areas that require unit tests:
Example test structure for a utility function:
// For a model parsing utility
describe('detectModelProvider', () => {
it('should detect anthropic provider for claude models', () => {
expect(detectModelProvider('claude-3-sonnet')).toBe('anthropic');
});
it('should default to openai for unknown models', () => {
expect(detectModelProvider('unknown-model')).toBe('openai');
});
});
When adding tests, ensure proper mocking of external dependencies and use appropriate test setup (providers, wrappers) to avoid test environment issues. Tests should cover both happy path scenarios and error cases to maintain code reliability.
Enter the URL of a public GitHub repository