diff options
| author | Igor Minar | 2012-01-06 18:39:03 -0800 | 
|---|---|---|
| committer | Vojta Jina | 2012-01-09 13:17:48 -0800 | 
| commit | 67338ce06140f60fe08bf59f7eb6c9814743e907 (patch) | |
| tree | 1c2e76a5b5db08e276d0aeb5cf623d8beb499a6a /test/angular-mocksSpec.js | |
| parent | 23f8da7cbb59c8f53f0f5c1e48102faeb4b7fd85 (diff) | |
| download | angular.js-67338ce06140f60fe08bf59f7eb6c9814743e907.tar.bz2 | |
feat($http): turn mock backend into a decorator + e2e testing support
- provider -> decorator
- autoflush + passThrough mode
- fix noop -> angular.noop
Diffstat (limited to 'test/angular-mocksSpec.js')
| -rw-r--r-- | test/angular-mocksSpec.js | 47 | 
1 files changed, 41 insertions, 6 deletions
| diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 32cfe933..9c0bd681 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -375,12 +375,19 @@ describe('mocks', function() {    describe('$httpBackend', function() { -    var hb, callback; - -    beforeEach(inject(function($httpBackend) { -      callback = jasmine.createSpy('callback'); -      hb = $httpBackend; -    })); +    var hb, callback, realBackendSpy; + +    beforeEach(inject( +        function($provide) { +          realBackendSpy = jasmine.createSpy('realBackend'); +          $provide.value('$httpBackend', realBackendSpy); +          $provide.decorator('$httpBackend', angular.module.ngMock.$httpBackendDecorator) +        }, +        function($httpBackend) { +          callback = jasmine.createSpy('callback'); +          hb = $httpBackend; +        } +    ));      it('should respond with first matched definition', function() { @@ -676,6 +683,34 @@ describe('mocks', function() {      }); +    describe('definitions with passThrough delegation', function() { +      it('should delegate requests to the real backend when passThrough is invoked', function() { +        hb.when('GET', /\/passThrough\/.*/).passThrough(); + +        expect(hb('GET', '/passThrough/23', null, callback)); +        expect(realBackendSpy). +            toHaveBeenCalledOnceWith('GET', '/passThrough/23', null, callback, undefined); +      }); +    }); + + +    describe('autoflush', function() { +      it('should flush responses via $defer when autoflush is turned on', inject( +          function($browser) { +        expect(hb.autoflush()).toBe(false); +        hb.autoflush(true); +        expect(hb.autoflush()).toBe(true); + +        hb.when('GET', '/foo').respond('bar'); +        hb('GET', '/foo', null, callback); + +        expect(callback).not.toHaveBeenCalled(); +        $browser.defer.flush(); +        expect(callback).toHaveBeenCalledOnce(); +      })); +    }); + +      describe('verifyExpectations', function() {        it('should throw exception if not all expectations were satisfied', function() { | 
