diff options
| author | Vojta Jina | 2011-10-31 11:36:31 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-11-30 11:17:23 -0500 | 
| commit | a4c8ac7126aab33ac0d8296a7495475363a0ea9b (patch) | |
| tree | b080f787f0986cac50ebc138a3336a3bf578d3b3 /test/angular-mocksSpec.js | |
| parent | e3e2e4436e27f69da080a5aaf06e1eb7909880cb (diff) | |
| download | angular.js-a4c8ac7126aab33ac0d8296a7495475363a0ea9b.tar.bz2 | |
feat(mock.$httpBackend): throw when nothing to flush, dump data/headers when expected different
Diffstat (limited to 'test/angular-mocksSpec.js')
| -rw-r--r-- | test/angular-mocksSpec.js | 31 | 
1 files changed, 25 insertions, 6 deletions
| diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 183c7d74..3ab8e757 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -531,7 +531,8 @@ describe('mocks', function() {        expect(function() {          hb('GET', '/match', null, noop, {}); -      }).toThrow('Expected GET /match with different headers'); +      }).toThrow('Expected GET /match with different headers\n' + +                 'EXPECTED: {"Content-Type":"application/json"}\nGOT: {}');      }); @@ -541,7 +542,8 @@ describe('mocks', function() {        expect(function() {          hb('GET', '/match', 'different', noop, {}); -      }).toThrow('Expected GET /match with different data'); +      }).toThrow('Expected GET /match with different data\n' + +                 'EXPECTED: some-data\nGOT: different');      }); @@ -589,11 +591,22 @@ describe('mocks', function() {        hb.when('GET').then(200, '');        hb('GET', '/url', null, callback); -      expect(function() {hb.flush(2);}).toThrow('No more pending requests'); +      expect(function() {hb.flush(2);}).toThrow('No more pending request to flush !');        expect(callback).toHaveBeenCalledOnce();      }); +    it('(flush) should throw exception when no request to flush', function() { +      expect(function() {hb.flush();}).toThrow('No pending request to flush !'); + +      hb.when('GET').then(200, ''); +      hb('GET', '/some', null, callback); +      hb.flush(); + +      expect(function() {hb.flush();}).toThrow('No pending request to flush !'); +    }); + +      it('respond() should set default status 200 if not defined', function() {        callback.andCallFake(function(status, response) {          expect(status).toBe(200); @@ -713,12 +726,18 @@ describe('mocks', function() {        it('should remove all responses', function() { -        hb.expect('GET', '/url').respond(200, '', {}); -        hb('GET', '/url', null, callback, {}); +        var cancelledClb = jasmine.createSpy('cancelled'); + +        hb.expect('GET', '/url').respond(200, ''); +        hb('GET', '/url', null, cancelledClb);          hb.resetExpectations(); + +        hb.expect('GET', '/url').respond(300, ''); +        hb('GET', '/url', null, callback, {});          hb.flush(); -        expect(callback).not.toHaveBeenCalled(); +        expect(callback).toHaveBeenCalledOnce(); +        expect(cancelledClb).not.toHaveBeenCalled();        });      }); | 
