-
Notifications
You must be signed in to change notification settings - Fork 0
Advanced Topics: Testing
Effective testing is an integral part of maintaining code quality and ensuring the functionality of your enhancements or bug fixes. This guide will walk you through our testing methodology, tools, and best practices to help you get started with writing and running tests for error-enhanced.
We primarily use Jest as our testing framework due to its flexibility, ease of use, and integration with TypeScript.
To run the existing test suite, execute the following command:
npm run testThis will execute all unit and integration tests, providing a summary of test cases that passed or failed.
Unit tests focus on testing individual modules or functions in isolation. When writing unit tests for error-enhanced, make sure to:
- Cover all edge cases.
- Check for both expected successes and failures.
Example:
import { ErrorEnhanced, IdentifiersEnhancer } from '@labrynx/error-enhanced';
describe('IdentifiersEnhancer', () => {
it('should generate a unique identifier', () => {
const error = new ErrorEnhanced([
new IdentifiersEnhancer()
]);
expect(typeof error.id).toBe('string');
expect(error.id).toHaveLength(36); // Assuming UUID
});
});Integration tests aim to test the interaction between multiple components. These tests are crucial for ensuring that the various enhancers and utilities work well together.
Example:
import { ErrorEnhanced, IdentifiersEnhancer, Severity } from '@labrynx/error-enhanced';
describe('Integration Test', () => {
it('should correctly set and retrieve enhanced properties', () => {
const error = new ErrorEnhanced([
new IdentifiersEnhancer()
]);
error.setErrorCode(404).setSeverity(Severity.HIGH);
expect(error.id).toBeDefined();
expect(error.errorCode).toBe(404);
expect(error.severity).toBe(Severity.HIGH);
});
});- Always write tests before fixing a bug or adding a new feature.
- Keep your tests small and focused.
- Mock external dependencies to ensure tests run quickly and are not flaky.
For any further questions or issues, please consult the FAQs or feel free to contribute to the repository.
Feel free to navigate through other topics using the sidebar, or you can return to the Home page for an overview.
error-enhanced Wiki
Version: 1.2.1 - © 2023
🔗 MIT License | 📦 GitHub Repository | 🐞 Report Issues | ✉️ Contact