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

1.2 Testing Angular Components

In this lesson we’ll add some basic unit tests for an existing Angular component using Jasmine, and then run them from the command line with Grunt and Karma.

To easily get an instance of the controller attached to the component, we can use the $componentController service. We can inject it into our tests using the inject method and save it to a variable. We wrap a service in underscores when injecting it, and Angular knows to unwrap it for us. See the code snippet below for an example.

Code Snippet

beforeEach(inject(function (_$rootScope_, _$componentController_) {
    $rootScope = _$rootScope_;
    $scope = $rootScope.$new();
    $componentController = _$componentController_;

    sandbox = sinon.sandbox.create();

Related Links

1.Testing Angular Components
2 lessons, 17:48

Free Lesson

Testing Angular Components