Project Requirements: Refactoring with Pure Functions
Overview
Revisit your capstone project and refactor it by extracting logic into pure functions. This project will help you practice writing testable, reusable code using Vitest.
Goals
- Refactor existing code by extracting logic into pure functions
- Write comprehensive tests for your functions
- Improve code organization and testability
- Practice using Vitest for testing
Requirements
1. Setup
2. Identify Refactoring Opportunities
3. Plan Your Functions
For each function you plan to create:
4. Create and Test Functions
5. Integrate Functions into Project
6. Additional Testing
Challenges (Optional)
Challenge 1: Component Testing
Challenge 2: Component Refactoring
Deliverables
- Refactored code with at least 3 pure functions
- Test files with comprehensive test coverage
- Module file (e.g.,
helpers.js) containing your functions
- Updated project that uses the new functions
- Documentation of function inputs/outputs (can be in code comments or README)
Success Criteria
- ✅ At least 3 pure functions created and tested
- ✅ All tests pass (green)
- ✅ Functions are properly documented (inputs/outputs)
- ✅ Old code is replaced with function calls
- ✅ Project still functions correctly after refactoring
- ✅ Edge cases are tested
Resources
Notes
- Pure functions should:
- Always return the same output for the same input
- Have no side effects
- Not depend on external state
- Be easy to test
- When refactoring:
- Start with one function at a time
- Write tests first (red-green-refactor cycle)
- Test thoroughly before integrating
- Keep the original functionality intact