diff options
| author | Vojta Jina | 2011-10-31 20:34:03 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-11-30 11:17:23 -0500 | 
| commit | afbe073121f13a23dc33a1d958c0a964029dc6ee (patch) | |
| tree | 471cdface7115d066f3a0e6a6397bd24912a6cc8 | |
| parent | 7b705df2b77bbd5e112b976a7a9630327aa77aca (diff) | |
| download | angular.js-afbe073121f13a23dc33a1d958c0a964029dc6ee.tar.bz2 | |
feat(mock.$httpBackend): add verifyNoOutstandingRequest method
+ rename verifyExpectations to verifyNoOutstandingExpectation
| -rw-r--r-- | src/angular-mocks.js | 8 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 2 | ||||
| -rw-r--r-- | test/angular-mocksSpec.js | 26 | ||||
| -rw-r--r-- | test/service/httpSpec.js | 2 | 
4 files changed, 28 insertions, 10 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js index e2348f6b..4cf4236c 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -664,12 +664,18 @@ angular.module.ngMock.$HttpBackendProvider = function() {        }      }; -    $httpBackend.verifyExpectations = function() { +    $httpBackend.verifyNoOutstandingExpectation = function() {        if (expectations.length) {          throw Error('Unsatisfied requests: ' + expectations.join(', '));        }      }; +    $httpBackend.verifyNoOutstandingRequest = function() { +      if (responses.length) { +        throw Error('Unflushed requests: ' + responses.length); +      } +    }; +      $httpBackend.resetExpectations = function() {        expectations = [];        responses = []; diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 5d91bf3e..eb458c2d 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -20,7 +20,7 @@ describe("resource", function() {    );    afterEach(inject(function($httpBackend) { -    $httpBackend.verifyExpectations(); +    $httpBackend.verifyNoOutstandingExpectation();    }));    it("should build resource", function() { diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 3ab8e757..cb11d355 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -559,7 +559,7 @@ describe('mocks', function() {        hb.flush();        expect(callback).toHaveBeenCalled(); -      expect(function() { hb.verifyExpectations(); }).not.toThrow(); +      expect(function() { hb.verifyNoOutstandingExpectation(); }).not.toThrow();      }); @@ -651,7 +651,7 @@ describe('mocks', function() {        hb('GET', '/some-url', null, callback);        hb.flush();        expect(callback).toHaveBeenCalledOnce(); -      hb.verifyExpectations(); +      hb.verifyNoOutstandingExpectation();      }); @@ -680,7 +680,7 @@ describe('mocks', function() {      }); -    describe('verify', function() { +    describe('verifyExpectations', function() {        it('should throw exception if not all expectations were satisfied', function() {          hb.expect('POST', '/u1', 'ddd').respond(201, '', {}); @@ -689,7 +689,7 @@ describe('mocks', function() {          hb('POST', '/u1', 'ddd', noop, {}); -        expect(function() {hb.verifyExpectations();}) +        expect(function() {hb.verifyNoOutstandingExpectation();})            .toThrow('Unsatisfied requests: GET /u2, POST /u3');        }); @@ -697,7 +697,7 @@ describe('mocks', function() {        it('should do nothing when no expectation', function() {          hb.when('DELETE', '/some').then(200, ''); -        expect(function() {hb.verifyExpectations();}).not.toThrow(); +        expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();        }); @@ -709,7 +709,19 @@ describe('mocks', function() {          hb('GET', '/u2', noop);          hb('POST', '/u3', noop); -        expect(function() {hb.verifyExpectations();}).not.toThrow(); +        expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow(); +      }); +    }); + +    describe('verifyRequests', function() { + +      it('should throw exception if not all requests were flushed', function() { +        hb.when('GET').then(200); +        hb('GET', '/some', null, noop, {}); + +        expect(function() { +          hb.verifyNoOutstandingRequest(); +        }).toThrow('Unflushed requests: 1');        });      }); @@ -721,7 +733,7 @@ describe('mocks', function() {          hb.expect('POST', '/u3').respond(201, '', {});          hb.resetExpectations(); -        expect(function() {hb.verifyExpectations();}).not.toThrow(); +        expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();        }); diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js index 12921992..72fd5f8e 100644 --- a/test/service/httpSpec.js +++ b/test/service/httpSpec.js @@ -19,7 +19,7 @@ describe('$http', function() {    afterEach(function() {      if ($exceptionHandler.errors.length) throw $exceptionHandler.errors; -    $httpBackend.verifyExpectations(); +    $httpBackend.verifyNoOutstandingExpectation();    });  | 
