Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 08cd5c1

Browse files
shahatapkozlowski-opensource
authored andcommitted
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
1 parent 41dc7d5 commit 08cd5c1

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/ngMock/angular-mocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
11421142
return function() {
11431143
return angular.isNumber(status)
11441144
? [status, data, headers, statusText]
1145-
: [200, status, data];
1145+
: [200, status, data, headers];
11461146
};
11471147
}
11481148

test/ngMock/angular-mocksSpec.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -1059,17 +1059,6 @@ describe('ngMock', function() {
10591059
expect(callback).toHaveBeenCalledOnceWith(200, 'first', 'header: val', 'OK');
10601060
});
10611061

1062-
it('should take function', function() {
1063-
hb.expect('GET', '/some').respond(function(m, u, d, h) {
1064-
return [301, m + u + ';' + d + ';a=' + h.a, {'Connection': 'keep-alive'}, 'Moved Permanently'];
1065-
});
1066-
1067-
hb('GET', '/some', 'data', callback, {a: 'b'});
1068-
hb.flush();
1069-
1070-
expect(callback).toHaveBeenCalledOnceWith(301, 'GET/some;data;a=b', 'Connection: keep-alive', 'Moved Permanently');
1071-
});
1072-
10731062
it('should default status code to 200', function() {
10741063
callback.andCallFake(function(status, response) {
10751064
expect(status).toBe(200);
@@ -1085,6 +1074,24 @@ describe('ngMock', function() {
10851074
expect(callback.callCount).toBe(2);
10861075
});
10871076

1077+
it('should default status code to 200 and provide status text', function() {
1078+
hb.expect('GET', '/url1').respond('first', {'header': 'val'}, 'OK');
1079+
hb('GET', '/url1', null, callback);
1080+
hb.flush();
1081+
1082+
expect(callback).toHaveBeenCalledOnceWith(200, 'first', 'header: val', 'OK');
1083+
});
1084+
1085+
it('should take function', function() {
1086+
hb.expect('GET', '/some').respond(function(m, u, d, h) {
1087+
return [301, m + u + ';' + d + ';a=' + h.a, {'Connection': 'keep-alive'}, 'Moved Permanently'];
1088+
});
1089+
1090+
hb('GET', '/some', 'data', callback, {a: 'b'});
1091+
hb.flush();
1092+
1093+
expect(callback).toHaveBeenCalledOnceWith(301, 'GET/some;data;a=b', 'Connection: keep-alive', 'Moved Permanently');
1094+
});
10881095

10891096
it('should default response headers to ""', function() {
10901097
hb.expect('GET', '/url1').respond(200, 'first');

0 commit comments

Comments
 (0)