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

h3ndr1ks picture h3ndr1ks · Sep 11, 2014 · Viewed 12.5k times · Source

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.

Answer

Buzzy picture Buzzy · Sep 15, 2014

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