diff options
| author | Igor Minar | 2011-12-28 10:27:38 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-01-09 13:17:48 -0800 |
| commit | b911e303ecad8b7b54589e26f3c551395bf47405 (patch) | |
| tree | 118d0b7a6872f96f42de68dfb69e39dba56de4c0 | |
| parent | a13b5ed3bc337a493029815c595b89c39eb95af6 (diff) | |
| download | angular.js-b911e303ecad8b7b54589e26f3c551395bf47405.tar.bz2 | |
feat($httpBackend): add expect/when shortcut methods
| -rw-r--r-- | src/angular-mocks.js | 15 | ||||
| -rw-r--r-- | test/angular-mocksSpec.js | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js index b4a1cbbc..419d66a0 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -671,6 +671,9 @@ angular.module.ngMock.$HttpBackendProvider = function() { }; }; + createShortMethods('when'); + + $httpBackend.expect = function(method, url, data, headers) { var expectation = new MockHttpExpectation(method, url, data, headers); expectations.push(expectation); @@ -681,6 +684,9 @@ angular.module.ngMock.$HttpBackendProvider = function() { }; }; + createShortMethods('expect'); + + $httpBackend.flush = function(count) { if (!responses.length) throw Error('No pending request to flush !'); @@ -715,6 +721,15 @@ angular.module.ngMock.$HttpBackendProvider = function() { }; return $httpBackend; + + + function createShortMethods(prefix) { + angular.forEach(['GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'JSONP'], function(method) { + $httpBackend[prefix + method] = function(url, data, headers) { + return $httpBackend[prefix](method, url, data, headers) + } + }); + } }; }; diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 88e6a590..32cfe933 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -750,6 +750,21 @@ describe('mocks', function() { }); + describe('expect/when shorcuts', function() { + angular.forEach(['expect', 'when'], function(prefix) { + angular.forEach(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'JSONP'], function(method) { + var shortcut = prefix + method; + it('should provide ' + shortcut + ' shortcut method', function() { + hb[shortcut]('/foo').respond('bar'); + hb(method, '/foo', undefined, callback); + hb.flush(); + expect(callback).toHaveBeenCalledOnceWith(200, 'bar', ''); + }); + }); + }); + }); + + describe('MockHttpExpectation', function() { it('should accept url as regexp', function() { |
