Reputation: 9411
I have many tests in Jasmine and Karma that rely on $httpBackend HTTP mocking checks. When I upgrdaded Angular today, they stopped to work.
Suppose I have something like this inside my Jasmine test:
// Arrange
httpBackend.expect('POST', 'https://localhost:44300/api/projects/1/samples').respond(fakedDto);
// Act
scope.updateSamples();
httpBackend.flush();
and on the last line, that was perfectly ok before, I receive:
TypeError: $browser.$$checkUrlChange is not a function in C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js (line 12502)
$RootScopeProvider/this.$get</Scope.prototype.$digest@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:12502:9
createHttpBackendMock/$httpBackend.flush@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular-mocks/angular-mocks.js:1481:5
@C:/SVN/samplemgmt/src/ClientApp/tests/integration/sample/samplecreationController_integration.test.js:341:9
Moreover, I have usual configuration to wrap up tests:
afterEach(function () {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
});
that now started to generate the following error:
Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.2.25/$rootScope/inprog?p0=%24digest in C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js (line 78)
minErr/<@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:78:5
beginPhase@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:13009:9
$RootScopeProvider/this.$get</Scope.prototype.$digest@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:12500:9
createHttpBackendMock/$httpBackend.verifyNoOutstandingExpectation@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular-mocks/angular-mocks.js:1514:5
@C:/SVN/samplemgmt/src/ClientApp/tests/integration/sample/samplecreationController_integration.test.js:137:9
I appreciate some suggestions how to make things work again. Are there any changes made to httpBackend testing lately?
Upvotes: 7
Views: 1548
Reputation: 1638
For those who are stuck with old Angular and can't upgrade at this point for some reason, here is a great post that explains what's going on and how to solve the problem.
To summarize -
The issue happens because both $httpBackend.flush()
and $httpBackend.verifyNoOutstandingExpectation()
mistakenly try to do digest. Obviously, the inner one (from verifyNoOutstandingExpectation()
call) fails. Luckily, we can instruct it not to perform digest - note the false
parameter:
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation(false); // <-- here
$httpBackend.verifyNoOutstandingRequest();
});
Upvotes: 7
Reputation: 9411
Solved: Angular-Mocks had to be updated manually (not using bower..) at that point.
Upvotes: 0