From d658d6766e673036baf6a5962c76912026f4f8c6 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Sun, 20 Jul 2014 01:32:27 +0300 Subject: [PATCH] fix(ngMock): respond did not always take a statusText argument minor fix so that `respond` can take a `statusText` argument even when having status 200 by default --- src/ngMock/angular-mocks.js | 2 +- test/ngMock/angular-mocksSpec.js | 24 ++++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index f91bb1006c05..2ce348ae614b 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -1097,7 +1097,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) { return function() { return angular.isNumber(status) ? [status, data, headers, statusText] - : [200, status, data]; + : [200, status, data, headers]; }; } diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 9934c37db6a2..3b22b8b2e27a 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -1110,6 +1110,14 @@ describe('ngMock', function() { expect(callback).toHaveBeenCalledOnceWith(200, 'first', 'header: val', 'OK'); }); + it('should default status code to 200', function() { + hb.expect('GET', '/url1').respond('first', {'header': 'val'}, 'OK'); + hb('GET', '/url1', null, callback); + hb.flush(); + + expect(callback).toHaveBeenCalledOnceWith(200, 'first', 'header: val', 'OK'); + }); + it('should take function', function() { hb.expect('GET', '/some').respond(function (m, u, d, h) { return [301, m + u + ';' + d + ';a=' + h.a, {'Connection': 'keep-alive'}, 'Moved Permanently']; @@ -1121,22 +1129,6 @@ describe('ngMock', function() { expect(callback).toHaveBeenCalledOnceWith(301, 'GET/some;data;a=b', 'Connection: keep-alive', 'Moved Permanently'); }); - it('should default status code to 200', function() { - callback.andCallFake(function(status, response) { - expect(status).toBe(200); - expect(response).toBe('some-data'); - }); - - hb.expect('GET', '/url1').respond('some-data'); - hb.expect('GET', '/url2').respond('some-data', {'X-Header': 'true'}); - hb('GET', '/url1', null, callback); - hb('GET', '/url2', null, callback); - hb.flush(); - expect(callback).toHaveBeenCalled(); - expect(callback.callCount).toBe(2); - }); - - it('should default response headers to ""', function() { hb.expect('GET', '/url1').respond(200, 'first'); hb.expect('GET', '/url2').respond('second');