aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2011-11-01 13:21:00 -0700
committerIgor Minar2011-11-30 11:17:23 -0500
commite9f81b66316854bdd3a8548f028a64e86fc3e73c (patch)
treeefbcd07af8a8061bd850570818957a5ee78b59ca
parentafbe073121f13a23dc33a1d958c0a964029dc6ee (diff)
downloadangular.js-e9f81b66316854bdd3a8548f028a64e86fc3e73c.tar.bz2
fix(mock.$httpBackend): flush() even requests sent during callbacks
-rw-r--r--src/angular-mocks.js13
-rw-r--r--test/angular-mocksSpec.js5
-rw-r--r--test/widgetsSpec.js2
3 files changed, 11 insertions, 9 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js
index 4cf4236c..17d317b7 100644
--- a/src/angular-mocks.js
+++ b/src/angular-mocks.js
@@ -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()();
}
};
diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js
index cb11d355..5b24c440 100644
--- a/test/angular-mocksSpec.js
+++ b/test/angular-mocksSpec.js
@@ -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();
});
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index c3bc1333..36e94947 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -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');