mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-25 02:40:24 +00:00
fix(mock.$httpBackend): flush() even requests sent during callbacks
This commit is contained in:
parent
afbe073121
commit
e9f81b6631
3 changed files with 11 additions and 9 deletions
13
src/angular-mocks.js
vendored
13
src/angular-mocks.js
vendored
|
|
@ -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()();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
5
test/angular-mocksSpec.js
vendored
5
test/angular-mocksSpec.js
vendored
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue