From 67338ce06140f60fe08bf59f7eb6c9814743e907 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 6 Jan 2012 18:39:03 -0800 Subject: feat($http): turn mock backend into a decorator + e2e testing support - provider -> decorator - autoflush + passThrough mode - fix noop -> angular.noop --- test/angular-mocksSpec.js | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'test/angular-mocksSpec.js') 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() { -- cgit v1.2.3