Refactoring for Testability: Pure Functions and Dependency Injection
Code that is easy to test is usually easier to reason about and change. Testability often means: pure logic in small functions, explicit dependencies (injection), and clear boundaries between "what to unit test" and "what to cover with integration or E2E." This post covers how to refactor toward that.
Pure functions first
Pure functions (same inputs → same output, no side effects) are the easiest to test: call with given inputs, assert the output. No mocks, no DOM, no async.