Right off the bat, and just so we’re clear about this: I read an “Early Release” edition of Mark Ethan Trostler’s Testable JavaScript, and in a lot of places… it shows. I’m sure it will come through editing and be a lot tighter by the time you read it.
Putting its rough “Early Release” nature aside, I had some mixed feelings about this book. I’ll try to explain it as follows:
Rebecca Murphey (@rmurphey) did a talk during the 2012 JavaScript Summit (put on by E4H) which was titled “Writing Testable JavaScript”. Early on in that talk, she impressed upon us that she was going to talk about how to write testable JavaScript, and not how to write JavaScript tests, nor how to test JavaScript. These are important distinctions. Writing tests (in a way) is this weird hybrid of somehow both writing more code and writing documentation. And testing your code is … well, it’s the act of putting your code through the accompanying tests to see if they pass muster. But writing testable code is about adopting a certain style wherein your code becomes easier to test as a consequence of that style. And the argument goes that if your code is easier to test, then it will also be easier to reason about. (Insert functional programming rant here.) Continue reading →