Key Concepts

Review core concepts you need to learn to master this subject

What is Jest?

Jest is a testing framework for JavaScript that includes both a test-runner and assertion functions in one package.

Unit Testing with Jest
Lesson 1 of 1
  1. 1
    As developers, we strive to make our code bulletproof from bugs that could break our applications. One process that can help us get closer to “unbreakable code” is testing while _testing framewor…
  2. 2
    Before we can begin testing our code with Jest, the jest package must first be installed and configured. We will download Jest via the Node Package Manager (NPM) by running the followin…
  3. 3
    Before we move on to actually writing our tests, we should cover a few best practices. By default, each test produces the terminal output that we saw in the previous exercise. Jest allows us to c…
  4. 4
    Now that Jest is installed and configured it is time to set up our first unit test. A unit test is designed to test the smallest unit of your code, like a single function. Let’s consider testing …
  5. 5
    With our test() container set up, it is time to finish our first unit test by writing assertions to validate the various features of our code. To do this, Jest provides the expect() function. T…
  6. 6
    Congrats on writing your first unit test! In the last exercise, you used the expect() assertion function along with the .toEqual() matcher method. Let’s learn about a few more common matcher method…
  7. 7
    Armed with how to write simple unit tests, we will now add a layer of complexity by exploring how to test asynchronous code in Jest. Let’s return to the findRecipes() function from the recipes mo…
  8. 8
    We will now explore testing functions that return a Promise. Let’s return to the findRecipe() function altere…
  9. 9
    Over the past few exercises, we have been analyzing the findRecipe() function which makes an REST API call to fetch the recipe data. Testing with a real REST API is not ideal for a few reasons: * …
  10. 10
    Now that we have a module set up with our mocked function it’s time to use it within our Jest test for findRecipe(). Remember, we want to replace the actual apiRequest() function with the mocked on…
  11. 11
    Great work! We have covered a lot over this lesson. Let’s take a moment to review: * We have learned that Jest is an easy-to-use framework for testing in a JavaScript environment because it combine…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo