Nodejs Express - unit testing/integration tests with Jest
4.4 (253 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
3,894 students enrolled

Nodejs Express - unit testing/integration tests with Jest

Learn to build a full CRUD REST API with Nodejs using TDD in Jest in JavaScript, with unit testing and integration test
4.4 (253 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
3,893 students enrolled
Created by Stefan Hyltoft
Last updated 11/2019
English
English [Auto]
Current price: $119.99 Original price: $199.99 Discount: 40% off
1 day left at this price!
30-Day Money-Back Guarantee
This course includes
  • 3 hours on-demand video
  • 1 article
  • 10 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Learn how to make unit tests
  • Learn how to make integration tests
  • Learn how to create a Express REST API from scratch
  • Learn how to build a Express REST API with test-driven development
  • Learn how to mock Mongoose models in Nodejs with Jest
  • Learn how to use Jest with TDD to build a REST API
  • Learn how to use MongoDB with Mongoose together with Jest tests
  • Learn how to write tests for error handling
Course content
Expand all 62 lectures 02:47:54
+ Hello world Express And Jest in less than 10 minutes!
4 lectures 07:17

Learn how to initialise our NodeJs Express test-driven development project with Jest

Preview 01:18

Learn how to create a simple Nodejs Express REST API in just 10 minutes!

Preview 03:50

A brieft introduction to the various REST HTTP Methods we can use inside the Nodejs Express REST API.

CRUD Methods we are going to build the TDD-way in REST
01:30

How to install Jest to use with Nodejs Express for test-driven development

Preview 00:39
+ Our first unit test with Jest
3 lectures 06:32

Making our first test with Jest for Nodejs Express REST API with test-driven development

Preview 03:55

Making our first test with Jest for Nodejs Express REST API with test-driven development PASS

Preview 01:16

How to setup Jest to automatically run on file changes in our Nodejs Express app

Make Jest run automatically on file changes
01:21
+ Our first unit tests for HTTP POST /todos
9 lectures 25:26

Defining our Mongoose/MongoDB model to use with our Express REST API.

Defining a data model for our Todo items with Mongoose
03:27

How to use jest.fn() to mock functions in our Mongoose model to verify that our Express controller has called the model correctly

Using jest.fn to mock our Mongoose model functions
04:04

Making our jest.fn() to mock functions in our Mongoose model to verify that our Express controller has called the model correctly

Making our test with Jest mock model pass
01:40

How to setup our Jest test environment correctly when using Mongoose inside Nodejs Express.

How to configure Jest test environment
01:28

How to use node-mocks-http package to verify that our Nodejs Express Request and Response objects have been used correctly

How to mock Request and Response objects in Express API
03:22

How to write a Jest test with node-mocks-http Request object with the Express controller and making the test pass

Writing test with mock Request object and making it pass!
02:45
Using beforeEach in Jest tests
01:17

How can we test if the response status code is set correctly and that the response is actually being sent back in Nodejs Express with Jest?

Testing if response code is 201 and response is sent
02:36

How to test if JSON body is being sent back correctly in our Nodejs Express REST API with Jest

Test if response is sending back JSON body
04:47
+ First integration test on HTTP POST /todos
13 lectures 34:17
Creating our first integration test with Supertest and Jest
06:35
How to make our Express app ready for integration testing
01:49
Creating our Express Router
03:15
How to debug tests in Jest
02:08
Setting up Express JSON request body middleware
01:00
Fix for address already in use error
01:04
Making our controller function use async/await
03:00
Setting up our MongoDB database in the cloud!
02:03
Creating a MongoDB database user
01:24
Connect to MongoDB database with Mongoose
03:17
Modify our unit tests to use async/await
03:29
Creating a server.js for running our Express REST API manually
02:08
Manual Testing with Postman
03:05
+ How to write error handling unit tests + integration tests
8 lectures 15:19
Oops! We're missing error handling!
02:55
Unit tests for error handling
03:16
Making our error handling unit test PASS
00:54
Creating a integration test for error handling
01:41
Manual test for error handling
01:14
Making a test for errors returning JSON body
00:47
Create middleware to parse errors in JSON
02:30
Making all of our tests pass and final manual test!
02:02
+ HTTP GET on /todos route
7 lectures 19:38
Intro + first test exercise
01:26
Making first test for getTodos pass
01:36
Test if TodoModel.find is called
03:22
Test if response is being sent back correctly
04:33
Test for error handling
03:47
Integration test for GET /todos
03:58
Manual test with Postman
00:56
+ HTTP GET on /todos/:todoId
8 lectures 24:25
Intro + Getting first test done
02:42
Creating mock function TodoModel.findById and test for calls
03:14
Exercise! Make test for response and make test pass!
01:43
Solution to response testing with getById()
04:19
Error handling unit test
02:53
If TodoModel could not be found in database
02:30
Integration test for GET /todos/:todoId
03:57
404 Integration test + final manual tests
03:07
+ HTTP PUT /todos - the TDD way
6 lectures 17:25
Intro to PUT method and first test
01:06
Test if TodoModel.findByIdAndUpdate is called
04:49
Test if PUT response is sent back
03:06
Test HTTP PUT error handling
02:17
HTTP PUT 404 test
02:09
HTTP PUT Integration test
03:58
+ HTTP DELETE
4 lectures 17:35
Using Jest.mock instead of multiple Jest.fn + Intro to final challenge!
02:58
Unit tests for HTTP Delete method
08:14
Integration test for HTTP Delete Method + manual test + you are awesome!!
06:11
BONUS - coupons for other courses
00:12
Requirements
  • Basic JavaScript ES6
  • Some familiarity with Nodejs Express is a plus
Description

Learn how to write a full CRUD REST API with Nodejs, Express and Jest using the test-driven development method!

TDD is becoming more and more of standard, and for good reasons!

With TDD, you can feel more safe and secure that any changes you make are not breaking existing functionality in your applications. Manual tests cannot be sustainable in large applications, or even medium applications. Plus, they're incredibly tedious.

Without TDD... well, you know the story. You try to add functionality while trying to touch the existing code as little as possible, because you don't want to break things unintentionally..

With TDD you won't be scared to make big refactors in your code to clean up messy code, you will know quickly if you've broken any existing functionality!

I'll show you step-by-step how to create a REST API with Express with unit tests and integration tests using the Jest test framework. There's going to be lots of opportunities for you to work on your own and do some exercises as well for optimal learning!

If you have any questions or suggestions to the course, feel free to message me anytime, I love interacting with my students!

Who this course is for:
  • Students somewhat familiar with Nodejs who wants to learn how to make production-ready software with TDD