Summary
This has definitely been a crash course on testing, but the groundwork has been laid and I hope that you have a solid understanding of the tool chain that you can use to write your own tests. We installed the Mocha test framework and wrote our first tests for Node.js. Using a custom testhelper.js
file, we integrated the various libraries and frameworks necessary to write tests for our code. These tools included Chai.js to write our assertions and Sinon.js for our spies and stubs. Trust this powerhouse suite of tools and you'll be writing bulletproof code in no time!
The ultimate goal with writing tests is to have 100 percent complete code coverage and have unit tests exist for every line of code you write. From here, the true test is to switch to TDD, which dictates that you write tests before any code exists at all. Obviously, tests against nonexistent code will fail, so then you'll need to write the least amount of code to get it to pass, and repeat!
In the next chapter...