From 568574b915086bcb1f08e3f8903ef79497c97435 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 4 Feb 2011 13:00:46 -0800 Subject: mock's .xhr.flush() should throw exception when there is nothing to flush --- src/angular-mocks.js | 4 ++++ test/servicesSpec.js | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 71a18d06..bbdcc94d 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -142,6 +142,10 @@ function MockBrowser() { self.xhr.expectPUT = angular.bind(self, self.xhr.expect, 'PUT'); self.xhr.expectJSON = angular.bind(self, self.xhr.expect, 'JSON'); self.xhr.flush = function() { + if (requests.length == 0) { + throw new Error("No xhr requests to be flushed!"); + } + while(requests.length) { requests.pop()(); } diff --git a/test/servicesSpec.js b/test/servicesSpec.js index a081882d..70645caf 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -723,7 +723,6 @@ describe("service", function(){ $browserXhr.expectGET('/url').respond('ERROR'); cache('GET', '/url', null, callback); $browser.defer.flush(); - $browserXhr.flush(); expect(log).toEqual('"first";"first";'); cache('GET', '/url', null, callback, false); -- cgit v1.2.3