Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 832 of the free egghead.io lessons, plus get Angular 1.x content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Testing a Controller

1:12 Angular 1.x lesson by

AngularJS provides helpers for convenient testing of your application. In this lesson you will learn how to test a basic controller with Jasmine and Angular.

Get the Code Now
click to level up

egghead.io comment guidelines

John Lindquist: To test a controller, we're going to start the same way we always start, with a beforeEach for our module, a beforeEach for the injection, and we'll inject in the controller provider. Then we can get the app control right here, which we'll get off of our module, and we will create our app controller.

From here, we'll split him, move it up, probably seen that happen a million times now, and we'll describe our app controller.

Basically, we're just going to say it should have a message of "Hello", and then we can expect our appCtrl.message to be "Hello". This should fail nicely for us, and we'll say this message is "Hello", and it passes.

That's kind of the same setup as always, module, inject, use a controller provider, get the controller, and then start running some tests against it. We'll go into more controller tests soon.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?