jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())
Solution 1
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
Solution 2
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.
Related videos on Youtube
h3ndr1ks
Updated on June 07, 2022Comments
-
h3ndr1ks almost 2 years
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.
-
Buzzy over 9 yearsI just had the same issue. I think this is a bug in 1.2.24, downgrading to 1.2.23 solved it.
-
h3ndr1ks over 9 yearsThanks, I downgraded to 1.2.23 and it works
-
DuelistPlayer over 9 years@Buzzy you should put that as answer...
-
-
Michael Draper over 9 yearsI just want to say this helped me tremendously. Thank you so much.
-
Junior Oliveira over 9 yearsyou helped me too, tks ^^
-
Natus Drew about 9 yearsI am still getting this error with the versions being set to the same 1.3.14
-
Tek almost 9 yearsWorked for me as well. Thanks