Refactoring Components
summary
Refactors a date-formatting helper from moment to date-fns using characterization tests to lock current behavior (including a discovered bug where 0 returns an empty string) and a try/catch to preserve it; runs ~7–8 tests that protect a function used in over 300 places. Evaluates snapshot tests (when they help and where they lie), extracts a NumberInput component from a large product page, and adds a new “plants” product — tests pass and the change lands cleanly.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:02Speaker introduction
- 2:08Talk overview
- 2:50What is refactoring
- 4:15When to refactor
- 5:17Refactoring costs and risks
- 6:42Refactoring safely
- 8:05Refactoring moment.js to date-fns
- 9:29Characterization tests
- 19:59Testing JSX with snapshots
- 26:50Snapshot test limitations
- 27:55Live refactoring demo
- 41:28Adding new features after refactor
- 43:55Key takeaways
