From b911e303ecad8b7b54589e26f3c551395bf47405 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 28 Dec 2011 10:27:38 -0800 Subject: feat($httpBackend): add expect/when shortcut methods --- src/angular-mocks.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') 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) + } + }); + } }; }; -- cgit v1.2.3