Jest
Begin testing quickly with Jest.
StartKey Concepts
Review core concepts you need to learn to master this subject
What is Jest?
Installing Jest
Configuring Jest
The test()
function
Detecting false positives
Testing async code: callbacks
Testing async code: Promises
Mocking functions with jest.fn()
What is Jest?
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
- 1As 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…
- 2Before 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…
- 3Before 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…
- 4Now 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 …
- 5With 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…
- 6Congrats 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…
- 7Armed 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…
- 8We will now explore testing functions that return a Promise. Let’s return to the findRecipe() function altere…
- 9Over 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: * …
- 10Now 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…
- 11Great 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
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory