From the course: Node.js: Testing and Code Quality
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Test doubles and Express apps
From the course: Node.js: Testing and Code Quality
Test doubles and Express apps
- [Instructor] Let's write some functional tests using an express app. There are a few steps necessary to do this. If you want to take a look at a reference or just copy the file, it can be found in the exercise files. When you're ready, switch over to VS code. We're going to be functionally testing reservations. So in the Explorer, navigate to the Route folder. Right click and select New file. We'll be testing the reservations route, so this will be named reservations.test.js. We'll start off by requiring SuperTest which we'll use for HTTP assertions. So const request equals require SuperTest. We'll create a placeholder for the app itself, which will be wrapped with SuperTest in a before all. So let app, and then a semi-colon. We also want to silence Morgan, the HTTP requests logger, so it doesn't clutter our test output with log messages. So we use const mock Morgan is a jest function which is an express middleware,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Why code coverage matters5m 22s
-
(Locked)
Measuring code coverage with Jest5m 54s
-
(Locked)
Functional testing with Jest4m 1s
-
(Locked)
Test doubles and Express apps5m 53s
-
(Locked)
Form submissions with SuperTest6m 9s
-
(Locked)
Fallacies of 100% test coverage4m 19s
-
(Locked)
Coverage with continuous integration4m 34s
-
(Locked)
Challenge: Isolate routes for faster tests39s
-
(Locked)
Solution: Isolate routes for faster tests9m 27s
-
(Locked)
-