fix(mock.$httpBackend): flush() even requests sent during callbacks

This commit is contained in:
Vojta Jina 2011-11-01 13:21:00 -07:00 committed by Igor Minar
parent afbe073121
commit e9f81b6631
3 changed files with 11 additions and 9 deletions

13
src/angular-mocks.js vendored
View file

@ -657,10 +657,15 @@ angular.module.ngMock.$HttpBackendProvider = function() {
$httpBackend.flush = function(count) {
if (!responses.length) throw Error('No pending request to flush !');
count = count || responses.length;
while (count--) {
if (!responses.length) throw Error('No more pending request to flush !');
responses.shift()();
if (angular.isDefined(count)) {
while (count--) {
if (!responses.length) throw Error('No more pending request to flush !');
responses.shift()();
}
} else {
while (responses.length)
responses.shift()();
}
};

View file

@ -563,15 +563,14 @@ describe('mocks', function() {
});
it('flush() should not flush requests fired during callbacks', function() {
// regression
it('flush() should flush requests fired during callbacks', function() {
hb.when('GET').then(200, '');
hb('GET', '/some', null, function() {
hb('GET', '/other', null, callback);
});
hb.flush();
expect(callback).not.toHaveBeenCalled();
expect(callback).toHaveBeenCalled();
});

View file

@ -567,8 +567,6 @@ describe("widget", function() {
$httpBackend.expect('GET', 'viewPartial.html').respond('content');
$httpBackend.flush();
myApp.$digest();
$httpBackend.flush();
expect(myApp.$element.text()).toEqual('include: view: content');
expect($route.current.template).toEqual('viewPartial.html');