Testing a Controller

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 10 years ago
Updated 5 years ago

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.

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.

Michael
Michael
~ 7 years ago

ReferenceError: 'module' is undefined at Anonymous function (http://localhost:63342/ngArchitecture-02-sub-modules/src/spec/PlayerSpec.js:50:9) at addSpecsToSuite (http://localhost:63342/ngArchitecture-02-sub-modules/src/bower_components/jasmine-core/lib/jasmine-core/jasmine.js:867:9) at describe (http://localhost:63342/ngArchitecture-02-sub-modules/src/bower_components/jasmine-core/lib/jasmine-core/jasmine.js:836:7) at jasmineInterface.describe (http://localhost:63342/ngArchitecture-02-sub-modules/src/bower_components/jasmine-core/lib/jasmine-core/jasmine.js:3576:7) at Anonymous function (http://localhost:63342/ngArchitecture-02-sub-modules/src/spec/PlayerSpec.js:48:5) at addSpecsToSuite (http://localhost:63342/ngArchitecture-02-sub-modules/src/bower_components/jasmine-core/lib/jasmine-core/jasmine.js:867:9) at describe (http://localhost:63342/ngArchitecture-02-sub-modules/src/bower_components/jasmine-core/lib/jasmine-core/jasmine.js:836:7) at jasmineInterface.describe (http://localhost:63342/ngArchitecture-02-sub-modules/src/bower_components/jasmine-core/lib/jasmine-core/jasmine.js:3576:7) at Global code (http://localhost:63342/ngArchitecture-02-sub-modules/src/spec/PlayerSpec.js:1:1)

Markdown supported.
Become a member to join the discussionEnroll Today