$browser.$$checkUrlChange is undefined in a jasmine test

All we need is an easy explanation of the problem, so here it is.

I have the following test:

it('should maintain a bind between the data at the $scope to the data at the ingredientsService', function(){
    $scope.addFilters('val1', $scope.customFiltersData, 'filter1');
    $scope.$digest();
    expect($scope.customFiltersData).toEqual(ingredientsService.filters());
});

I get the following error:

TypeError: undefined is not a function
    at Scope.$digest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12502:17)
    at null.<anonymous> (/home/oleg/dev/vita-webapp-new/test/spec/controllers/customfilters.js:92:20)

When debugging I saw that $browser.$$checkUrlChange on line 12502 of angular.js is indeed undefined.

As a temporary solution, I changed the invocation on line 1250 to $browser.$$checkUrlChange && $browser.$$checkUrlChange()

But I cannot help to wonder whether this monkey-patch can hurt me in some other way.

Any clue on how to solve this properly is much appreciated.

In case I do not get my answers I might consider opening a bug at the Angular repo on GitHub.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You have a mismatch in the version of angular and angular-mock .
See here:

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

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply