The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Test an Angular Component with $componentController

Test an Angular Component with $componentController

3:56
Traditionally you had to create DOM elements to test a directive but by shifting our focus to components, writing unit tests got a lot easier using **$componentController** within **ngMocks**. We can now test our component's controller with an easy to use API that does not require us to spin up any DOM elements to do so. In this lesson, we will see how our ES6 tests are transpiled, learn how to test a component using **$componentController** and talk about how to simulate lifecycle hooks.
Watch this lesson now
Avatar
egghead.io

Traditionally you had to create DOM elements to test a directive but by shifting our focus to components, writing unit tests got a lot easier using $componentController within ngMocks. We can now test our component's controller with an easy to use API that does not require us to spin up any DOM elements to do so. In this lesson, we will see how our ES6 tests are transpiled, learn how to test a component using $componentController and talk about how to simulate lifecycle hooks.

Avatar
Krishna Gopinath

Hello, first of all, thanks for this! I learnt a lot from it.

I tried following the same pattern and got to a good point with it, but now, I'm trying to get some unit testing done, I seem to be facing some issues. I've specified the problem here, in this StackOverflow question: http://stackoverflow.com/questions/42880087/injectorunpr-unknown-provider-error-when-testing-with-jasmine

Following the same model that you have, I have a ThemesModel that I am injecting into a GameController, but I seem to be getting an $injector:unpr Unknown provider error. Ideally, this means that I have a dependency issue lurking somewhere but I seem to be unable to find it! Any help would be greatly appreciated. Thanks :)

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?