Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Before writing unit tests, the application you're testing must be configured in such a way that you can test all of the end points. It's also helpful to supply some sample data you know won't change. In this video, we'll configure our application and add some sample data. Let's go to the Exercise files > Chapter 6 > Video 3 and then copy the Start folder to the desktop. Next, > Terminal, and change directory to that folder. And now I'm going to type npm install.
So the first thing I'm going to do, is create a Test folder in my Start folder. This folder is going to contain all of my unit tests as well as all the helper files I'll build to help run them. In the Exercise files, I have some sample data. This is just a set a three flights that I know won't change. Copy this Data folder into the Test folder. Now let's add a Helpers folder. This folder is going to contain an app.js file, which I'm going to use to simulate the application that we already have built.
So let's open this up in our Text Editor. In the Helpers folder, I'm going to create a file, and I'm going to call it app.js. The first thing I'm going to include is the original application So to do that, I'm going to require, I'm going to go down two levels so I can find the app.js file. And now I'm going to include the sample data. I want to include the data in this folder, rather than the data we've been using. So I'm just going to go down one level. And then finally, I want to export this application that's bound with these flights.
So, to do that I'm going to type in module.exports. And then I'm going to set that to the result of calling the application with the flights. Now, let's create a file that will help us test whether or not all this works. We're also going to use this file later on to write actual unit tests. I'm going to create a file in the Test folder, and I'm going to call it lightspeck.js. And all I'm going to do for now on this file, is create a variable called app, and I'm going to set it to requiring helpers app.
So, let's go to the command line and run this file to make sure there are no errors. I'm changing directory to test and now I'm going to type node and flight spec.js. And now I'm going to press Return. No errors came up, so we're good to go. The app helper we've written binds the application to the set of sample data we've added. In the next video we'll install unit testing tools and write some tests.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101483 Viewers
61 Video lessons · 88250 Viewers
71 Video lessons · 72117 Viewers
56 Video lessons · 103881 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.