Mô tả

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!

Bạn sẽ học được gì

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

Yêu cầu

  • Basic JavaScript ES6
  • Some familiarity with Nodejs Express is a plus

Nội dung khoá học

9 sections

Hello world Express And Jest in less than 10 minutes!

4 lectures
Initialising project
01:18
Hello World Express REST API in less than 5 mins!
03:50
CRUD Methods we are going to build the TDD-way in REST
01:30
Short intro to Jest + How to install Jest in our project
00:39

Our first unit test with Jest

3 lectures
Our first test with Jest and Express REST API
03:55
Making our first test with Jest + Express REST API pass!
01:16
Make Jest run automatically on file changes
01:21

Our first unit tests for HTTP POST /todos

9 lectures
Defining a data model for our Todo items with Mongoose
03:27
Using jest.fn to mock our Mongoose model functions
04:04
Making our test with Jest mock model pass
01:40
How to configure Jest test environment
01:28
How to mock Request and Response objects in Express API
03:22
Writing test with mock Request object and making it pass!
02:45
Using beforeEach in Jest tests
01:17
Testing if response code is 201 and response is sent
02:36
Test if response is sending back JSON body
04:47

First integration test on HTTP POST /todos

13 lectures
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
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
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
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
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
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

Đánh giá của học viên

Chưa có đánh giá
Course Rating
5
0%
4
0%
3
0%
2
0%
1
0%

Bình luận khách hàng

Viết Bình Luận

Bạn đánh giá khoá học này thế nào?

image

Đăng ký get khoá học Udemy - Unica - Gitiho giá chỉ 50k!

Get khoá học giá rẻ ngay trước khi bị fix.