Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())

I have a following controller:

.controller('ProjectUserAddCtrl', ['$scope', 'ProjectUser', '$q', 'i18nNotifications',      function($scope, ProjectUser, $q, i18nNotifications) {     var buildUnassignedUsers = function(users, project) {         var unassignedUsers = [];         angular.forEach(users, function(user) {             var match;             angular.forEach(project.projectUsers, function(projectUser) {                 if(match) {return;}                 if(projectUser.user.id === user.id) {                     match = true;                 }             });              if(!match) {                 unassignedUsers.push(user);             }         });          $scope.unassignedUsers = unassignedUsers;     };           $q.all([             $scope.users,             $scope.project     ]).then(function(result) {             buildUnassignedUsers($scope.users, $scope.project);             $scope.$watch('project', function(newVal) {                  buildUnassignedUsers($scope.users, $scope.project); }, true             );     }); }]); 

And a following test in jasmine:

describe('ProjectUserAddCtrl', function() {     var ctrl;     beforeEach(function(){         $scope.users = [];         $scope.project = {             projectUsers: []         };         ctrl = $controller('ProjectUserAddCtrl', {$scope:$scope, ProjectUser:ProjectUser, $q:$q, i18nNotifications:i18nNotifications});     });      it('should create a new instance', function() {         expect(ctrl).toBeDefined();     });      // this test fails!     it('should create a list of unassigned users', function() {         $scope.$apply(); // need to call apply to resolve promises         expect($scope.unassignedUsers).toBeDefined();     });  }); 

'should create a list of unassigned users' test fails with this error:

TypeError: 'undefined' is not a function(evaluating $browser.$$checkUrlChange())

I really have no idea why. Any help appreciated.

like image 838
h3ndr1ks Avatar asked Sep 11 '14 10:09

h3ndr1ks


2 Answers

It seems this issue happens when you have mismatch between angular.js and angular-mocks.js Make sure the two files are of the same version.

Please ignore my original comment to the question

like image 56
Buzzy Avatar answered Sep 21 '22 19:09

Buzzy


I had experienced exactly the same issues with our rails project.

We upgraded angular.js to 1.2.24, and then our teaspoon testsuite started failing. I looked into angular.js sources/commits story etc., and then realized, that we had forgot to update angular mocks (we were using old 1.2.20 version, so we need to run bundle update rails-assets-angular-mocks to force this change). After applying new mocks (they already have $$checkUrlChange function mock) everything started working.

So It looks like you also try to use old mocks objects.

like image 33
Vitali Tsevan Avatar answered Sep 18 '22 19:09

Vitali Tsevan