Skip to content

Commit 3ec4310

Browse files
committed
DO NOT MERGE alternative to angular#13128 wrt tests
1 parent 7c792f4 commit 3ec4310

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

src/ng/http.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1261,16 +1261,16 @@ function $HttpProvider() {
12611261
}
12621262
}
12631263

1264-
function resolveHttpPromise() {
1264+
// function resolveHttpPromise() {
12651265
resolvePromise(response, status, headersString, statusText);
1266-
}
1267-
1268-
if (useApplyAsync) {
1269-
$rootScope.$applyAsync(resolveHttpPromise);
1270-
} else {
1271-
resolveHttpPromise();
1272-
if (!$rootScope.$$phase) $rootScope.$apply();
1273-
}
1266+
// }
1267+
1268+
// if (useApplyAsync) {
1269+
// $rootScope.$applyAsync(resolveHttpPromise);
1270+
// } else {
1271+
// resolveHttpPromise();
1272+
// if (!$rootScope.$$phase) $rootScope.$apply();
1273+
// }
12741274
}
12751275

12761276

test/ng/directive/ngIncludeSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ describe('ngInclude', function() {
372372
$httpBackend.expectGET('include.svg').respond('<rect></rect><rect></rect>');
373373
element = $compile('<svg><test></test></svg>')($rootScope);
374374
$httpBackend.flush();
375+
$httpBackend.flush();
375376
var child = element.find('rect');
376377
expect(child.length).toBe(2);
377378
expect(child[0] instanceof SVGRectElement).toBe(true);

test/ng/httpSpec.js

+25-22
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe('$http', function() {
293293
$httpBackend = $hb;
294294
$http = $h;
295295
$rootScope = $rs;
296-
spyOn($rootScope, '$apply').andCallThrough();
296+
spyOn($rootScope, '$evalAsync').andCallThrough();
297297
}]));
298298

299299
it('should throw error if the request configuration is not an object', function() {
@@ -1012,31 +1012,37 @@ describe('$http', function() {
10121012
});
10131013

10141014

1015-
describe('scope.$apply', function() {
1015+
describe('$rootScope.$evalAsync', function() {
10161016

1017-
it('should $apply after success callback', function() {
1018-
$httpBackend.when('GET').respond(200);
1019-
$http({method: 'GET', url: '/some'});
1020-
$httpBackend.flush();
1021-
expect($rootScope.$apply).toHaveBeenCalledOnce();
1017+
it('should $evalAsync after success callback', function() {
1018+
$httpBackend.whenGET().respond(200);
1019+
$http.get('/some');
1020+
$rootScope.$digest(); // Send the request
1021+
$rootScope.$evalAsync.reset();
1022+
$httpBackend.flush(null, false);
1023+
expect($rootScope.$evalAsync).toHaveBeenCalledOnce();
10221024
});
10231025

10241026

1025-
it('should $apply after error callback', function() {
1026-
$httpBackend.when('GET').respond(404);
1027-
$http({method: 'GET', url: '/some'});
1028-
$httpBackend.flush();
1029-
expect($rootScope.$apply).toHaveBeenCalledOnce();
1027+
it('should $evalAsync after error callback', function() {
1028+
$httpBackend.whenGET().respond(404);
1029+
$http.get('/some');
1030+
$rootScope.$digest(); // Send the request
1031+
$rootScope.$evalAsync.reset();
1032+
$httpBackend.flush(null, false);
1033+
expect($rootScope.$evalAsync).toHaveBeenCalledOnce();
10301034
});
10311035

10321036

1033-
it('should $apply even if exception thrown during callback', inject(function($exceptionHandler) {
1034-
$httpBackend.when('GET').respond(200);
1037+
it('should $evalAsync even if exception thrown during callback', inject(function($exceptionHandler) {
1038+
$httpBackend.whenGET().respond(200);
10351039
callback.andThrow('error in callback');
10361040

1037-
$http({method: 'GET', url: '/some'}).then(callback);
1038-
$httpBackend.flush();
1039-
expect($rootScope.$apply).toHaveBeenCalledOnce();
1041+
$http.get('/some');
1042+
$rootScope.$digest(); // Send the request
1043+
$rootScope.$evalAsync.reset();
1044+
$httpBackend.flush(null, false);
1045+
expect($rootScope.$evalAsync).toHaveBeenCalledOnce();
10401046

10411047
$exceptionHandler.errors = [];
10421048
}));
@@ -1921,9 +1927,7 @@ describe('$http', function() {
19211927

19221928
describe('$http with $applyAsync', function() {
19231929
var $http, $httpBackend, $rootScope, $browser, log;
1924-
beforeEach(module(function($httpProvider) {
1925-
$httpProvider.useApplyAsync(true);
1926-
}, provideLog));
1930+
beforeEach(module(provideLog));
19271931

19281932

19291933
beforeEach(inject(['$http', '$httpBackend', '$rootScope', '$browser', 'log', function(http, backend, scope, browser, logger) {
@@ -1939,15 +1943,14 @@ describe('$http with $applyAsync', function() {
19391943
}]));
19401944

19411945

1942-
it('should schedule coalesced apply on response', function() {
1946+
it('should defer response handling', function() {
19431947
var handler = jasmine.createSpy('handler');
19441948
$httpBackend.expect('GET', '/template1.html').respond(200, '<h1>Header!</h1>', {});
19451949
$http.get('/template1.html').then(handler);
19461950
// Ensure requests are sent
19471951
$rootScope.$digest();
19481952

19491953
$httpBackend.flush(null, false);
1950-
expect($rootScope.$applyAsync).toHaveBeenCalledOnce();
19511954
expect(handler).not.toHaveBeenCalled();
19521955

19531956
$browser.defer.flush();

0 commit comments

Comments
 (0)