JavaScript

Testing Basics

JavaScript Course

Introduction

Test Driven Development, or TDD for short, 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 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, 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.

Lesson overview

This section contains a general overview of topics that you will learn in this lesson.

  • Explain the basics of TDD.
  • Get up and running with Jest.
  • Write basic tests.

Assignment

  1. Read about the basic process and the benefits of TDD.
  2. Watch at least the first 3 videos of the Unit Testing in JavaScript video series.
  3. Follow along to Jest’s Getting Started tutorial. For the upcoming testing practice and project, you only need to follow the instructions for installing jest.
  4. 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.
  5. This article explains more about the why/how and value behind TDD and also includes some great examples of how to apply it.

Knowledge check

The following questions are an opportunity to reflect on key topics in this lesson. If you can’t answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge.

Additional resources

This section contains helpful links to related content. It isn’t required, so consider it supplemental.

  • It looks like this lesson doesn’t have any additional resources yet. Help us expand this section by contributing to our curriculum.

Support us!

The Odin Project is funded by the community. Join us in empowering learners around the globe by supporting The Odin Project!