Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Angular Controllers: Controller Not Defined

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)?

like image 399
Steve Ross Avatar asked Dec 08 '25 09:12

Steve Ross


1 Answers

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});
    }));
like image 81
rooftop Avatar answered Dec 09 '25 21:12

rooftop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!