Skip to main content

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
By connecting students all over the world to the best instructors, Udemy is helping individuals reach their goals and pursue their dreams. Udemy is the leading global marketplace for teaching and learning, connecting millions of students to the skills they need to succeed. Udemy helps organizations of all kinds prepare for the ever-evolving future of work. Our curated collection of top-rated business and technical courses gives companies, governments, and nonprofits the power to develop in-house expertise and satisfy employees’ hunger for learning and development.

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