Check out a free preview of the full JavaScript Testing Practices and Principles course
The "Unit Tests for Express Middleware" Lesson is part of the full, JavaScript Testing Practices and Principles course featured in this preview video. Here's what you'd learn in this lesson:
To test Express middleware that interacts with the database, Kent shows that one can either mock or initialize the database. In this demonstration, Kent initializes the database and asserts that the endpoints are returning the correct items from the database.
Transcript from the "Unit Tests for Express Middleware" Lesson
[00:00:00]
>> Kent Dodds: But I think it'd be cool to have you all do an exercise right now. Since, it looks like you wanna use your fingers on the keyboard. So for your stuff, you're actually gonna be in this same area, you'll just be doing the post, not to do.
>> Kent Dodds: And so to run those tests, you'll be in watch mode, hit the p key, and then controllers.*post.todo.
[00:00:26]
And I've already kind of set things up for you from the outline standpoint. Just do the first one, we'll just give you ten minutes just to do this first one. And then, we'll come back and I'll work through the solution. And then, we'll continue onto our next subject about test object factories.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops