refactoringjsbook

Technical Debt

The cost of fixing all the erros and problems with the code base

  • You need to have tests to verify that a certain behaviour dosesn't change to refactor

“Writing tests takes too long. We’re moving too fast for that.” “It’s extra code to maintain.” “That’s what QA is for.” “It doesn’t catch enough errors.” “It doesn’t catch the important errors.” “This is just a little script/simple change. It doesn’t need a test.” “But the code works.” “The boss/client is paying for features, not tests.” “No one else on the team cares and will break the test suite and I’ll be trying to be Commissioner Gordon in a Gotham gone mad.”

Reasons why you need to test (pg. 50)

  • You are already doing it
  • Refactoring is impossible without it
  • It makes working with a team easier
  • Tests are ideal for demonstrating functionality
  • You are not just verifying the behaviour of your code but other people's code
  • Tests are crucial for big upgrades
  • You will catch bugs early
  • Tests help smooth out development cycles
  • Your feedback loop will be tighter

Testing is hard, you already wrote code now you have to write code that uses the code in a comprehensive and structured way. This leads on to the larger problem of writing quality software. This is a hard task but there are decades of work done on this to aid you.

Gotchas in js

  • Cannot use === for arrays/objects but works fine for integers and strings e.g. ['2,' '3'] === ['2', '3'] will give false

Handy Commands

Watch files changes and test mocha -w filename