diff options
| author | Vojta Jina | 2012-01-11 11:15:00 -0800 | 
|---|---|---|
| committer | Vojta Jina | 2012-01-11 22:11:01 -0800 | 
| commit | 28114de8dcf86c69f533b924ce205533bc265786 (patch) | |
| tree | e4b76616205ea0f377f57123521076635506a403 /test/angular-mocksSpec.js | |
| parent | c6ea1be0536b9d4564f028554fd1762feba58994 (diff) | |
| download | angular.js-28114de8dcf86c69f533b924ce205533bc265786.tar.bz2 | |
refactor(mock.$httpBackend): split (e2e/unit testing version of $httpBackend mock)
Diffstat (limited to 'test/angular-mocksSpec.js')
| -rw-r--r-- | test/angular-mocksSpec.js | 86 | 
1 files changed, 47 insertions, 39 deletions
| diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 248bb108..fbdd3b91 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -1,6 +1,6 @@  'use strict'; -describe('mocks', function() { +describe('ngMock', function() {    describe('$browser', function() { @@ -373,19 +373,12 @@ describe('mocks', function() {    describe('$httpBackend', function() { -    var hb, callback, realBackendSpy; - -    beforeEach(inject( -        function($provide) { -          realBackendSpy = jasmine.createSpy('realBackend'); -          $provide.value('$httpBackend', realBackendSpy); -          $provide.decorator('$httpBackend', angular.mock.$httpBackendDecorator) -        }, -        function($httpBackend) { -          callback = jasmine.createSpy('callback'); -          hb = $httpBackend; -        } -    )); +    var hb, callback; + +    beforeEach(inject(function($httpBackend) { +      callback = jasmine.createSpy('callback'); +      hb = $httpBackend; +    }));      it('should respond with first matched definition', function() { @@ -681,31 +674,8 @@ 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(); -      })); +    it('should not have passThrough method', function() { +      expect(hb.passThrough).toBeUndefined();      }); @@ -856,3 +826,41 @@ describe('mocks', function() {      });    });  }); + + +describe('ngMockE2E', function() { +  describe('$httpBackend', function() { +    var hb, realHttpBackend, callback; + +    beforeEach(inject(function($provide, $injector) { +      callback = jasmine.createSpy('callback'); +      realHttpBackend = jasmine.createSpy('real $httpBackend'); +      $provide.value('$httpBackend', realHttpBackend); +      $provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator); +      hb = $injector.get('$httpBackend'); +    })); + + +    describe('passThrough()', function() { +      it('should delegate requests to the real backend when passThrough is invoked', function() { +        hb.when('GET', /\/passThrough\/.*/).passThrough(); +        hb('GET', '/passThrough/23', null, callback); + +        expect(realHttpBackend). +            toHaveBeenCalledOnceWith('GET', '/passThrough/23', null, callback, undefined); +      }); +    }); + + +    describe('autoflush', function() { +      it('should flush responses via $defer', inject(function($browser) { +        hb.when('GET', '/foo').respond('bar'); +        hb('GET', '/foo', null, callback); + +        expect(callback).not.toHaveBeenCalled(); +        $browser.defer.flush(); +        expect(callback).toHaveBeenCalledOnce(); +      })); +    }); +  }); +}); | 
