Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Testing a Controller

    John LindquistJohn Lindquist

    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.

    angularjsAngularJS
    jasmineJasmine
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss