3

My question is very similar to Testing Angular Controllers defined like angular.module('myApp').controller(. Rather than hijacking that question, I thought I would ask mine separately. when I use the proposed answer of the form:

describe('evCalcApp controllers', function(){
  beforeEach(module('evCalcApp.controllers'));
    var scope, ctrl
    beforeEach(inject(function($controller, $rootScope) {
      scope = $rootScope.$new();
      ctrl = $controller('MyMileageCalcController', {$scope: scope});
    }));

That works fine for the first controller. However, if you were testing more than one controller in the same file, how would you inject the second controller (let's just call it MyCtrl2)?

1 Answer 1

3

Same way you did the last one

describe('evCalcApp controllers', function(){
  beforeEach(module('evCalcApp.controllers'));
    var scope, ctrl, ctrl2;
    beforeEach(inject(function($controller, $rootScope) {
      scope = $rootScope.$new();
      scope2 = $rootScope.$new();
      ctrl = $controller('MyMileageCalcController', {$scope: scope});
      ctrl2 = $controller('MyCtrl2', {$scope: scope2});
    }));
Sign up to request clarification or add additional context in comments.

1 Comment

Great! Thanks. So it appears this cannot go inside the describe block for the given controller but rather must live inside the outer describe for the module. Right?

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.