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

Closes #8270
This commit is contained in:
Shahar Talmi
2014-07-20 01:32:27 +03:00
committed by Pawel Kozlowski
parent 41dc7d5ebd
commit 08cd5c19c7
2 changed files with 19 additions and 12 deletions

View File

@@ -1142,7 +1142,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
return function() {
return angular.isNumber(status)
? [status, data, headers, statusText]
: [200, status, data];
: [200, status, data, headers];
};
}

View File

@@ -1059,17 +1059,6 @@ describe('ngMock', function() {
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'];
});
hb('GET', '/some', 'data', callback, {a: 'b'});
hb.flush();
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);
@@ -1085,6 +1074,24 @@ describe('ngMock', function() {
expect(callback.callCount).toBe(2);
});
it('should default status code to 200 and provide status text', 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'];
});
hb('GET', '/some', 'data', callback, {a: 'b'});
hb.flush();
expect(callback).toHaveBeenCalledOnceWith(301, 'GET/some;data;a=b', 'Connection: keep-alive', 'Moved Permanently');
});
it('should default response headers to ""', function() {
hb.expect('GET', '/url1').respond(200, 'first');