0

I write Unit tests for angular controllers with Karma. It looks like:

describe('TestController', function() {

    var $scope, $rootScope, service1, sevice2, service3, $controller;

    beforeEach(module('TestModule'));

    beforeEach(function() {  
        inject(function($injector) {
            service1= $injector.get('service1');
            service2= $injector.get('service2');
            service3= $injector.get('service3');
            $scope = $injector.get('$rootScope').$new();

            $controller = $injector.get('$controller')('TestController', {
                $scope: $scope
            });            
        });
    });

    /* it blocks */
});

As can You see all controllers injects i get from $injector by hands, step by step.

So question is, can i simply get list of all TestController injects?

controller function sample for this test:

function($scope, $rootScope, service1, sevice2, service3)

i need get:

['$scope', '$rootScope', 'service1', 'sevice2', 'service3'] or similar

1 Answer 1

1

The annotate method of the injector object will give you a list of dependencies.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.