Skip to main content
CF

Nodejs Express - unit testing/integration tests with Jest

2h 48m 43s
English
Paid

Master the art of writing a full CRUD REST API using Node.js, Express, and Jest with the test-driven development (TDD) method! TDD is rapidly becoming a standard in software development for its ability to ensure safe and secure changes without breaking existing functionality. Manual testing is unsustainable for medium to large applications and can be extremely tedious.

Course Overview

Without TDD, changes can lead to unintentional breakages as developers hesitate to modify existing code. With TDD, you gain the confidence to execute significant code refactoring and clean-ups without fear. This course will guide you step-by-step in creating a REST API using Express with unit and integration tests powered by the Jest framework. You will have multiple opportunities to engage in hands-on exercises to enhance your learning.

Instructor Support

If you have any questions or suggestions regarding the course, feel free to reach out. I enjoy interacting with my students and am here to help you succeed!

Target Audience

Who this course is for:
  • Students familiar with Node.js seeking to create production-ready software using TDD

Course Requirements

Requirements:
  • Basic knowledge of JavaScript ES6
  • Some familiarity with Node.js Express is beneficial

Learning Objectives

What you'll learn:

  • How to create unit tests
  • How to perform integration tests
  • How to build an Express REST API from scratch
  • How to develop an Express REST API using test-driven development
  • How to mock Mongoose models in Node.js with Jest
  • How to leverage Jest with TDD to build a REST API
  • How to integrate MongoDB with Mongoose and Jest tests
  • How to write tests for error handling

About the Author: Udemy

Udemy thumbnail

Udemy is the largest open marketplace for online courses on the internet. Founded in 2010 by Eren Bali, Oktay Caglar, and Gagan Biyani and headquartered in San Francisco, the company went public on the Nasdaq in 2021 under the ticker UDMY. The platform hosts well over two hundred thousand courses across software development, IT and cloud, data science, design, business, marketing, and creative skills, taught by tens of thousands of independent instructors. Roughly seventy million learners use it worldwide, and the corporate arm — Udemy Business — supplies a curated subset of that catalog to enterprise customers.

Because Udemy is a marketplace rather than a single editorial publisher, the catalog is uneven by design. The strongest material lives in the long-form, project-based courses authored by working engineers — full-stack JavaScript, React, Node.js, Python data science, AWS, Docker and Kubernetes, mobile development with Flutter and React Native, and cloud certification preparation. The CourseFlix listing under this source is the slice of that catalog that has been mirrored here for offline-friendly viewing, organized by topic and updated as new releases land. Pricing on Udemy itself swings dramatically with the site's near-permanent sales, which is why the platform is best treated as a deep reference catalog: pick instructors with strong reviews and a track record of updating their material rather than buying on the headline price alone.

Watch Online 61 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 61 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Initialising project
All Course Lessons (61)
#Lesson TitleDurationAccess
1
Initialising project Demo
01:19
2
Hello World Express REST API in less than 5 mins!
03:51
3
CRUD Methods we are going to build the TDD-way in REST
01:31
4
Short intro to Jest + How to install Jest in our project
00:40
5
Our first test with Jest and Express REST API
03:56
6
Making our first test with Jest + Express REST API pass!
01:17
7
Make Jest run automatically on file changes
01:22
8
Defining a data model for our Todo items with Mongoose
03:28
9
Using jest.fn to mock our Mongoose model functions
04:05
10
Making our test with Jest mock model pass
01:41
11
How to configure Jest test environment
01:29
12
How to mock Request and Response objects in Express API
03:23
13
Writing test with mock Request object and making it pass!
02:46
14
Using beforeEach in Jest tests
01:18
15
Testing if response code is 201 and response is sent
02:37
16
Test if response is sending back JSON body
04:48
17
Creating our first integration test with Supertest and Jest
06:36
18
How to make our Express app ready for integration testing
01:50
19
Creating our Express Router
03:16
20
How to debug tests in Jest
02:09
21
Setting up Express JSON request body middleware
01:01
22
Fix for address already in use error
01:05
23
Making our controller function use async/await
03:01
24
Setting up our MongoDB database in the cloud!
02:04
25
Creating a MongoDB database user
01:25
26
Connect to MongoDB database with Mongoose
03:18
27
Modify our unit tests to use async/await
03:30
28
Creating a server.js for running our Express REST API manually
02:09
29
Manual Testing with Postman
03:06
30
Oops! We're missing error handling!
02:56
31
Unit tests for error handling
03:17
32
Making our error handling unit test PASS
00:55
33
Creating a integration test for error handling
01:42
34
Manual test for error handling
01:15
35
Making a test for errors returning JSON body
00:48
36
Create middleware to parse errors in JSON
02:31
37
Making all of our tests pass and final manual test!
02:03
38
Intro + first test exercise
01:27
39
Making first test for getTodos pass
01:37
40
Test if TodoModel.find is called
03:23
41
Test if response is being sent back correctly
04:34
42
Test for error handling
03:48
43
Integration test for GET /todos
03:59
44
Manual test with Postman
00:57
45
Intro + Getting first test done
02:43
46
Creating mock function TodoModel.findById and test for calls
03:15
47
Exercise! Make test for response and make test pass!
01:44
48
Solution to response testing with getById()
04:20
49
Error handling unit test
02:54
50
If TodoModel could not be found in database
02:31
51
Integration test for GET /todos/:todoId
03:58
52
404 Integration test + final manual tests
03:08
53
Intro to PUT method and first test
01:07
54
Test if TodoModel.findByIdAndUpdate is called
04:50
55
Test if PUT response is sent back
03:07
56
Test HTTP PUT error handling
02:18
57
HTTP PUT 404 test
02:10
58
HTTP PUT Integration test
03:59
59
Using Jest.mock instead of multiple Jest.fn + Intro to final challenge!
02:59
60
Unit tests for HTTP Delete method
08:15
61
Integration test for HTTP Delete Method + manual test + you are awesome!!
06:12
Unlock unlimited learning

Get instant access to all 60 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription

Related courses

Frequently asked questions

What are the prerequisites for this course?
This course requires a basic knowledge of JavaScript ES6 and some familiarity with Node.js. Having prior experience with Node.js Express is beneficial but not mandatory. These prerequisites ensure that you can follow along with the lessons on creating a REST API using Express and Jest.
What will I build during the course?
Throughout the course, you will build a full CRUD REST API using Node.js and Express. You will learn to implement unit and integration tests with Jest, providing a test-driven development (TDD) approach to ensure the API's reliability and robustness.
Who is the target audience for this course?
The course is designed for students who are already familiar with Node.js and are looking to create production-ready software using test-driven development (TDD). It is ideal for those wanting to enhance their skills in writing automated tests using Jest in a Node.js environment.
What specific tools and platforms are covered in the course?
The course covers Node.js, Express, and Jest as the primary tools. Additionally, you will use Mongoose for data modeling, Supertest for integration testing, and Postman for manual testing. MongoDB is the database platform used, with lessons on setting up a MongoDB database in the cloud.
What topics are not covered in this course?
The course does not cover advanced JavaScript topics beyond ES6, nor does it delve into frontend development or other backend frameworks outside of Express. It focuses solely on the backend development process using Node.js, Express, and Jest with a TDD approach.
How much time should I allocate to complete the course?
The course consists of 61 lessons, which include various hands-on exercises and tests. While the exact runtime is not specified, allocating time for both watching the lessons and practicing the exercises is essential to fully grasp the material. A commitment of several weeks, depending on your pace, is recommended.
How can the skills learned in this course benefit my career?
The skills learned in this course, such as building robust REST APIs with test-driven development, are highly transferable to many roles in software development. Mastering TDD with Jest in a Node.js environment prepares you for backend development positions and enhances your ability to maintain and refactor code safely.