Course info
Jun 13, 2015
1h 26m

Unit Testing is one of the best ways to improve the quality of your code. This course will walk you through all of the fundamentals of unit testing in Node.

About the author
About the author

Joe has been a web developer for the last 13 of his 16+ years as a professional developer. He has specialized in front end and middle tier development . Although his greatest love is writing code, he also enjoys teaching and speaking about code.

More from the author
Angular Fundamentals
9h 35m
Feb 1, 2019
Angular Crash Course
Nov 1, 2018
Unit Testing in Angular
3h 20m
Sep 6, 2018
More courses by Joe Eames
Section Introduction Transcripts
Section Introduction Transcripts

Hello. I'm Joe Eames and welcome to Pluralsight's course, Unit Testing with Node. js. I have long been a proponent of testing and have spent more than a decade teaching testing, unit testing, and test driven development in many different languages and platforms. This is one of my favorite subjects and something I'm extremely passionate about. I'm absolutely convinced that every project can benefit from effective unit testing and I hope that through this course, you will come to learn not only how to unit test in Node, but also why, and I'm grateful that you have chosen to spend this time with me. I'm sure you will find it to be well worth the effort. This course is a how-to guide on unit testing with Node. We will cover all of the basics of unit testing in Node, including the tools and techniques, the whys and wherefores, and the tips and tricks as well. We'll talk about how to unit test all of the typical pieces of Node, how to use unit tests to give you confidence in your code, and we'll also see how to write effective and easily maintained unit tests. We start out with this introductory module, which will cover some basics and theory about unit testing, then we'll talk about the tools that are used when unit testing Node, then we will get into the meat of this course, which is actually writing unit tests for your code that will include business logic, I/O promises, and lots more. This course is meant for Node developers who have anywhere from no experience with unit testing and want to learn from the ground up, to those who have quite a bit of unit testing experience, but want to round out their skillset. If unit testing in Node is an interest of yours, then this course is for you.

Tools for Unit Testing Node
Hello! I'm Joe Eames, and welcome to module 2 of Pluralsight's course, Unit Testing in Node. In this module, we're going to be talking about the different tools we use for unit testing Node. This will include both the libraries that we use when we're actually testing Node and task automation tools that we use in order to run our tests. These automation tools let us run our tests whenever we want and also watch our files and automatically rerun our tests whenever there's a change. This can be very advantageous because we now immediately know if we've broken anything as soon as we make any changes. In this module, we'll start off by talking about Mocha and Chai. Mocha is the testing framework we will use with Node and is the most popular one currently in use. There are some other frameworks used, but none are nearly as common as Mocha. Chai is the assertion library used by Mocha. Chai gives us the syntax to verify that things happen the way we expect. We'll become very familiar with Chai in this course. Next, we'll cover Sinon. Sinon is a mocking library and by far the most common one in JavaScript. It is extremely powerful yet easy to use. Then, we'll cover Gulp. Gulp is one of several different task runners that we can use to run our unit tests and automate them so that they run for us whenever we change our code. And, last, we'll cover Grunt, which is another task runner just like Gulp. Both of these task runners are very popular, so it's beneficial to know them both since you're likely to encounter both of them in typical development shops.

Unit Testing Your Code
Hello! In this module, we're going to be working on unit testing our code. That means we'll actually be writing tests against existing code. I'm going to use preexisting code that I've already written, but the code that I'm writing is far less important than understanding the lessons about writing unit tests for your code. In this module, we're going to cover the following topics. We'll start off with talking about how to test business logic and how to write good tests and make sure that your business logic itself is testable. Then we'll talk about how to test exceptions. There can certainly be places in your code where you will throw exceptions, and you need to be able to test that logic. Normally when you throw an exception, that fails a test. But with Mocha, we can manage that and are able to test code that throws exceptions. We'll also talk about finding edge cases and using our tests to find problems in our code and then using the tests to guide us into writing fixes for our code. After that, we'll talk about IO and Async operations. IO is typically an asynchronous operation in Node. And there are other asynchronous operations in Node that aren't directly IO related. We'll talk about how to test those with Mocha. After that, we'll talk about mocking our code. Mocking is very important to enable us to isolate the one unit of code that we want to work with. Sometimes this unit is a single class. Sometimes it might be two or three classes. But we need to make sure that we're only testing the code we want to test. And mocks enable that so that we don't test other code that we don't want running in our tests. Then we'll talk about testing promises, which has a few unique capabilities in Mocha. And, finally, we talk about test coverage, which gives us the ability to see what code we have tested and what code we haven't.