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 this short article that outlines the basic process and the benefits of TDD.
  2. 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. We will cover rest of the videos in our More Testing lesson.
  3. Read and follow the Getting Started tutorial on the main Jest website. 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.

Knowledge check

This section contains questions for you to check your understanding of this lesson on your own. If you’re having trouble answering a question, click it and review the material it links to.

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!