diff options
| -rw-r--r-- | src/angular-mocks.js | 2 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 2 | ||||
| -rw-r--r-- | test/angular-mocksSpec.js | 62 | ||||
| -rw-r--r-- | test/service/httpSpec.js | 20 |
4 files changed, 43 insertions, 43 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 17d317b7..d9535f64 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -639,7 +639,7 @@ angular.module.ngMock.$HttpBackendProvider = function() { var definition = new MockHttpExpectation(method, url, data, headers); definitions.push(definition); return { - then: function(status, data, headers) { + respond: function(status, data, headers) { definition.response = angular.isFunction(status) ? status : createResponse(status, data, headers); } }; diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index eb458c2d..fd7e41db 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -40,7 +40,7 @@ describe("resource", function() { it('should ignore slashes of undefinend parameters', inject(function($httpBackend) { var R = resource.route('/Path/:a/:b/:c'); - $httpBackend.when('GET').then('{}'); + $httpBackend.when('GET').respond('{}'); $httpBackend.expect('GET', '/Path'); $httpBackend.expect('GET', '/Path/1'); $httpBackend.expect('GET', '/Path/2/3'); diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 5b24c440..01c1b6ca 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -380,8 +380,8 @@ describe('mocks', function() { it('should respond with first matched definition', function() { - hb.when('GET', '/url1').then(200, 'content', {}); - hb.when('GET', '/url1').then(201, 'another', {}); + hb.when('GET', '/url1').respond(200, 'content', {}); + hb.when('GET', '/url1').respond(201, 'another', {}); callback.andCallFake(function(status, response) { expect(status).toBe(200); @@ -396,7 +396,7 @@ describe('mocks', function() { it('should throw error when unexpected request', function() { - hb.when('GET', '/url1').then(200, 'content'); + hb.when('GET', '/url1').respond(200, 'content'); expect(function() { hb('GET', '/xxx'); }).toThrow('Unexpected request: GET /xxx'); @@ -404,9 +404,9 @@ describe('mocks', function() { it('should match headers if specified', function() { - hb.when('GET', '/url', null, {'X': 'val1'}).then(201, 'content1'); - hb.when('GET', '/url', null, {'X': 'val2'}).then(202, 'content2'); - hb.when('GET', '/url').then(203, 'content3'); + hb.when('GET', '/url', null, {'X': 'val1'}).respond(201, 'content1'); + hb.when('GET', '/url', null, {'X': 'val2'}).respond(202, 'content2'); + hb.when('GET', '/url').respond(203, 'content3'); hb('GET', '/url', null, function(status, response) { expect(status).toBe(203); @@ -428,8 +428,8 @@ describe('mocks', function() { it('should match data if specified', function() { - hb.when('GET', '/a/b', '{a: true}').then(201, 'content1'); - hb.when('GET', '/a/b').then(202, 'content2'); + hb.when('GET', '/a/b', '{a: true}').respond(201, 'content1'); + hb.when('GET', '/a/b').respond(202, 'content2'); hb('GET', '/a/b', '{a: true}', function(status, response) { expect(status).toBe(201); @@ -446,7 +446,7 @@ describe('mocks', function() { it('should match only method', function() { - hb.when('GET').then(202, 'c'); + hb.when('GET').respond(202, 'c'); callback.andCallFake(function(status, response) { expect(status).toBe(202); expect(response).toBe('c'); @@ -462,7 +462,7 @@ describe('mocks', function() { it('should expose given headers', function() { - hb.when('GET', '/u1').then(200, null, {'X-Fake': 'Header', 'Content-Type': 'application/json'}); + hb.when('GET', '/u1').respond(200, null, {'X-Fake': 'Header', 'Content-Type': 'application/json'}); var xhr = hb('GET', '/u1', null, noop, {}); hb.flush(); expect(xhr.getResponseHeader('X-Fake')).toBe('Header'); @@ -471,8 +471,8 @@ describe('mocks', function() { it('should preserve the order of requests', function() { - hb.when('GET', '/url1').then(200, 'first'); - hb.when('GET', '/url2').then(201, 'second'); + hb.when('GET', '/url1').respond(200, 'first'); + hb.when('GET', '/url2').respond(201, 'second'); hb('GET', '/url2', null, callback); hb('GET', '/url1', null, callback); @@ -485,8 +485,8 @@ describe('mocks', function() { }); - it('then() should take function', function() { - hb.when('GET', '/some').then(function(m, u, d, h) { + it('respond() should take function', function() { + hb.when('GET', '/some').respond(function(m, u, d, h) { return [301, m + u + ';' + d + ';a=' + h.a, {'Connection': 'keep-alive'}]; }); @@ -516,7 +516,7 @@ describe('mocks', function() { expect(response).toBe('expect'); }); - hb.when('GET', '/url').then(200, 'when'); + hb.when('GET', '/url').respond(200, 'when'); hb.expect('GET', '/url').respond(300, 'expect'); hb('GET', '/url', null, callback, {}); @@ -526,7 +526,7 @@ describe('mocks', function() { it ('should throw exception when only headers differes from expectation', function() { - hb.when('GET').then(200, '', {}); + hb.when('GET').respond(200, '', {}); hb.expect('GET', '/match', undefined, {'Content-Type': 'application/json'}); expect(function() { @@ -537,7 +537,7 @@ describe('mocks', function() { it ('should throw exception when only data differes from expectation', function() { - hb.when('GET').then(200, '', {}); + hb.when('GET').respond(200, '', {}); hb.expect('GET', '/match', 'some-data'); expect(function() { @@ -547,13 +547,13 @@ describe('mocks', function() { }); - it('expect() should without respond() and use then()', function() { + it('expect() should without respond() and use respond()', function() { callback.andCallFake(function(status, response) { expect(status).toBe(201); expect(response).toBe('data'); }); - hb.when('GET', '/some').then(201, 'data'); + hb.when('GET', '/some').respond(201, 'data'); hb.expect('GET', '/some'); hb('GET', '/some', null, callback); hb.flush(); @@ -564,7 +564,7 @@ describe('mocks', function() { it('flush() should flush requests fired during callbacks', function() { - hb.when('GET').then(200, ''); + hb.when('GET').respond(200, ''); hb('GET', '/some', null, function() { hb('GET', '/other', null, callback); }); @@ -575,7 +575,7 @@ describe('mocks', function() { it('flush() should flush given number of pending requests', function() { - hb.when('GET').then(200, ''); + hb.when('GET').respond(200, ''); hb('GET', '/some', null, callback); hb('GET', '/some', null, callback); hb('GET', '/some', null, callback); @@ -587,7 +587,7 @@ describe('mocks', function() { it('flush() should throw exception when flushing more requests than pending', function() { - hb.when('GET').then(200, ''); + hb.when('GET').respond(200, ''); hb('GET', '/url', null, callback); expect(function() {hb.flush(2);}).toThrow('No more pending request to flush !'); @@ -598,7 +598,7 @@ describe('mocks', function() { it('(flush) should throw exception when no request to flush', function() { expect(function() {hb.flush();}).toThrow('No pending request to flush !'); - hb.when('GET').then(200, ''); + hb.when('GET').respond(200, ''); hb('GET', '/some', null, callback); hb.flush(); @@ -622,14 +622,14 @@ describe('mocks', function() { }); - it('then() should set default status 200 if not defined', function() { + it('respond() should set default status 200 if not defined', function() { callback.andCallFake(function(status, response) { expect(status).toBe(200); expect(response).toBe('some-data'); }); - hb.when('GET', '/url1').then('some-data'); - hb.when('GET', '/url2').then('some-data', {'X-Header': 'true'}); + hb.when('GET', '/url1').respond('some-data'); + hb.when('GET', '/url2').respond('some-data', {'X-Header': 'true'}); hb('GET', '/url1', null, callback); hb('GET', '/url2', null, callback); hb.flush(); @@ -644,7 +644,7 @@ describe('mocks', function() { expect(response).toBe('def-response'); }); - hb.when('GET').then(201, 'def-response'); + hb.when('GET').respond(201, 'def-response'); hb.expect('GET', '/some-url'); hb('GET', '/some-url', null, callback); @@ -671,7 +671,7 @@ describe('mocks', function() { it('should respond undefined when JSONP method', function() { - hb.when('JSONP', '/url1').then(200); + hb.when('JSONP', '/url1').respond(200); hb.expect('JSONP', '/url2').respond(200); expect(hb('JSONP', '/url1')).toBeUndefined(); @@ -694,7 +694,7 @@ describe('mocks', function() { it('should do nothing when no expectation', function() { - hb.when('DELETE', '/some').then(200, ''); + hb.when('DELETE', '/some').respond(200, ''); expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow(); }); @@ -703,7 +703,7 @@ describe('mocks', function() { it('should do nothing when all expectations satisfied', function() { hb.expect('GET', '/u2').respond(200, '', {}); hb.expect('POST', '/u3').respond(201, '', {}); - hb.when('DELETE', '/some').then(200, ''); + hb.when('DELETE', '/some').respond(200, ''); hb('GET', '/u2', noop); hb('POST', '/u3', noop); @@ -715,7 +715,7 @@ describe('mocks', function() { describe('verifyRequests', function() { it('should throw exception if not all requests were flushed', function() { - hb.when('GET').then(200); + hb.when('GET').respond(200); hb('GET', '/some', null, noop, {}); expect(function() { diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js index 72fd5f8e..8212eb07 100644 --- a/test/service/httpSpec.js +++ b/test/service/httpSpec.js @@ -411,7 +411,7 @@ describe('$http', function() { var future, rawXhrObject; beforeEach(function() { - $httpBackend.when('GET', '/url').then(''); + $httpBackend.when('GET', '/url').respond(''); future = $http({method: 'GET', url: '/url'}); rawXhrObject = MockXhr.$$lastInstance; spyOn(rawXhrObject, 'abort'); @@ -490,7 +490,7 @@ describe('$http', function() { } beforeEach(function() { - $httpBackend.when('GET').then(function(m, url) { + $httpBackend.when('GET').respond(function(m, url) { return [parseInt(url.substr(1)), '', {}]; }); }); @@ -658,7 +658,7 @@ describe('$http', function() { describe('scope.$apply', function() { it('should $apply after success callback', function() { - $httpBackend.when('GET').then(200); + $httpBackend.when('GET').respond(200); $http({method: 'GET', url: '/some'}); $httpBackend.flush(); expect(scope.$apply).toHaveBeenCalledOnce(); @@ -666,7 +666,7 @@ describe('$http', function() { it('should $apply after error callback', function() { - $httpBackend.when('GET').then(404); + $httpBackend.when('GET').respond(404); $http({method: 'GET', url: '/some'}); $httpBackend.flush(); expect(scope.$apply).toHaveBeenCalledOnce(); @@ -674,7 +674,7 @@ describe('$http', function() { it('should $apply even if exception thrown during callback', function() { - $httpBackend.when('GET').then(200); + $httpBackend.when('GET').respond(200); callback.andThrow('error in callback'); $http({method: 'GET', url: '/some'}).on('200', callback); @@ -687,7 +687,7 @@ describe('$http', function() { it('should broadcast $http.request', function() { - $httpBackend.when('GET').then(200); + $httpBackend.when('GET').respond(200); scope.$on('$http.request', callback); var xhrFuture = $http({method: 'GET', url: '/whatever'}); @@ -880,7 +880,7 @@ describe('$http', function() { describe('pendingRequests', function() { it('should be an array of pending requests', function() { - $httpBackend.when('GET').then(200); + $httpBackend.when('GET').respond(200); expect($http.pendingRequests.length).toBe(0); $http({method: 'get', url: '/some'}); @@ -892,7 +892,7 @@ describe('$http', function() { it('should remove the request when aborted', function() { - $httpBackend.when('GET').then(0); + $httpBackend.when('GET').respond(0); future = $http({method: 'get', url: '/x'}); expect($http.pendingRequests.length).toBe(1); @@ -904,7 +904,7 @@ describe('$http', function() { it('should remove the request when served from cache', function() { - $httpBackend.when('GET').then(200); + $httpBackend.when('GET').respond(200); $http({method: 'get', url: '/cached', cache: true}); $httpBackend.flush(); @@ -919,7 +919,7 @@ describe('$http', function() { it('should remove the request before firing callbacks', function() { - $httpBackend.when('GET').then(200); + $httpBackend.when('GET').respond(200); $http({method: 'get', url: '/url'}).on('xxx', function() { expect($http.pendingRequests.length).toBe(0); }); |
