Testing
Introduction
Test Driven Development is a big deal in the modern development landscape. This is a concept that we introduced way back in our Fundamentals section with our JavaScript Exercises. The main idea is simply that you start working on your code by writing automated tests before writing the code that is being tested. There are tons of benefits to working like this, all of which will be discussed in the resources below.
There are many test-running systems available in JavaScript: Mocha, Jasmine, Tape and Jest to name a few. Fortunately the syntax for each one is very similar. They all have their own set of special features, but the basic syntax is almost identical, so in the end it doesn't matter which one you use. In fact, simply picking which library to use for this curriculum has been quite tricky!
This lesson is going to center around Jest. The biggest reasons for this decision are that one of the best resources we've found for explaining JavaScript testing uses it and they have fantastic documentation. In the end, writing tests is less about the syntax and more about the TDD philosophy. The most important issues are knowing why we write tests and what we test rather than how.
Assignment
Read this short article that outlines the basic process and the benefits of TDD.
Watch at least the first 3 videos of this video series about testing in JavaScript. The first video focuses heavily on the WHY, while the next two go into more depth about the process. Later videos in the series are definitely worthwhile, but the first 3 are enough to get you up and running.
Read and follow the Getting Started tutorial on the main Jest website.
Read and follow the Using Matchers document on the main Jest website. This one demonstrates some of the other useful functions you can use in your tests.
Watch this amazing video that covers what to test in your codebase. The video is specifically about testing the Ruby language, but that doesn't matter at all. The concepts here ring true in any language, and luckily Ruby is a clear enough language that you will be able to follow along just fine. This video might be worth re-visiting after you've done some testing of your own.
Last updated