Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m

Next lesson playing in 5 seconds


Free Preview: Testing Angular Controllers


  • Overview
  • Transcript

Unit testing is a key tool for ensuring the correctness of our software. Angular apps are no exception! In fact, part of what makes Angular so amazing is that it is a framework written from the ground up with testing in mind.

If you haven't unit tested an Angular application before, you might not be aware that there are some extra features that we can use to make testing easier, such as hooking into Angular's dependency injection, and using angular-mocks for a range of test-friendly utilities.

In this Coffee Break Course, designed to teach a new skill or concept in a single sitting, Envato Tuts+ instructor Dan Wellman will show you how to take an existing Angular app and add tests for its controller. You'll learn how to create a new scope and how to create an instance of the controller and associate it with that scope. You'll also see how to inject dependencies and how to stub methods in dependencies.

Watch the other Coffee Break Courses in the Angular testing series:

We've built comprehensive guides to help you learn JavaScript, AngularJS, and Angular 2, whether you're just getting started or you want to explore more advanced topics.

1.Testing Angular Controllers
2 lessons, 13:31

Free Lesson

Testing Angular Controllers

1. Testing Angular Controllers

1.1 Introduction

[MUSIC] If you haven't tested an Angular application before, you might not be aware that there are a couple of extra features that we can make use of to make testing Angular apps easier. Such as hooking into Angular's Dependency Injection for our tests and using Angular marks for a range of test friendly utilities. So we're going to look at these to see how to use them. We'll also going to cover other essentials, such as creating a scope for the controller and a test using the rootScope service and using Sinon's Sandbox. Hi folks, I'm Dan Wellman. Welcome to Testing Angular Controllers. In this course, we're going to see how to add unit tests for an Angular controller using primarily Jasmine and Karma. If you're new to Angular, why not take a look at some of the great Angular content we have here on Tuts+. There's Building a Web App From Scratch With AngularJS by Andrew Burgess. If you're new to Jasmine, you can try my course, JavaScript Testing With Jasmine 2.0. We'll be adding some tests for an existing simple example JavaScript app. And we'll be using Grunt and Karma among other things. So to be prepared for the course you might need to install the latest version of Node and then cloneD Repository for the reference application. Once the clone is done, an npm install should install all of the project dependencies for you. So let's make a start with testing.