angular/angular.js — pull request #6522 by friedreiss (2014-03-03 03:56:56+00:00)
Title: Prevent duplicate $digest calls

Hello. Having some trouble here with a Jasmine test...

I'm testing an API service that uses ```$http```, and mocking the backend with ```$httpBackend```.

The test looks like this:

```javascript
/// api.js

.
.
.

describe('API #get()', function () {

afterEach(function () {
$httpBackend.verifyNoOutstandingRequest();
$httpBackend.verifyNoOutstandingExpectation(); // LINE 33
});

it('should return something falsy when the server does', function (done) {
$httpBackend.expect('GET', 'http://api.example.com/')
.respond({
'code': '200',
'data': {
'valid': false
}
});

API.get()
.then(function (valid) {
expect(valid).toBeFalsy();
done(); // LINE 52
});

$httpBackend.flush(); // LINE 55
});

});

});

.
.
.
```

And here's the stack trace. I labeled the notable lines in ```api.js``` above with a comment.

```
Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.2.12/$rootScope/inprog?p0=%24digest
at beginPhase (.../app/bower_components/angular/angular.js:12290)
at .../app/bower_components/angular/angular.js:11792
at .../app/bower_components/angular-mocks/angular-mocks.js:1484
at .../test/spec/services/api.js:33
at .../test/spec/services/api.js:52
at .../app/bower_components/angular/angular.js:10965
at .../app/bower_components/angular/angular.js:11051
at .../app/bower_components/angular/angular.js:11977
at .../app/bower_components/angular/angular.js:11803
at .../app/bower_components/angular/angular.js:12083
at done (.../app/bower_components/angular/angular.js:7841)
at handleResponse (.../app/bower_components/angular-mocks/angular-mocks.js:1130)
at .../app/bower_components/angular-mocks/angular-mocks.js:1461
at .../test/spec/services/api.js:55
```

The change that I'm PRing seems to fix everything (hopefully!), but I'm sure the experts have something different to say... (I'm doing this all wrong?)

Thanks for your time!