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

Commit 0377c6f

Browse files
committed
fix($compile): do not swallow thrown errors in test
In e13eeab, errors/rejections produced during fetching the template or compiling an asynchronous directive, where overzealously silenced. This doesn't make any difference in (most) production apps, where `$exceptionHandler` does not rethrow the errors. In tests though (where `$exceptionHandler` rethrows by default), it can unexpectedly "swallow" thrown errors. This commit fixes it by removing the extraneous `.catch(noop)`, thus letting errors thrown by `$exceptionHandler` to surface. The changes in 'compileSpec.js' essentially revert the modifications that were unnecessarily (and incorrectly) done in e13eeab (and also one incorrect modification from [c22615c][1]). [1]: c22615c#diff-348c2f3781ed66a24894c2046a52c628L2084 Fixes #15629 Closes #15631
1 parent 9c13866 commit 0377c6f

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

src/ng/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
31563156
if (error instanceof Error) {
31573157
$exceptionHandler(error);
31583158
}
3159-
}).catch(noop);
3159+
});
31603160

31613161
return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {
31623162
var childBoundTranscludeFn = boundTranscludeFn;

test/ng/compileSpec.js

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,15 +1881,14 @@ describe('$compile', function() {
18811881

18821882

18831883
it('should throw an error and clear element content if the template fails to load',
1884-
inject(function($compile, $exceptionHandler, $httpBackend, $rootScope) {
1884+
inject(function($compile, $httpBackend, $rootScope) {
18851885
$httpBackend.expect('GET', 'hello.html').respond(404, 'Not Found!');
18861886
element = $compile('<div><b class="hello">content</b></div>')($rootScope);
18871887

1888-
$httpBackend.flush();
1889-
1888+
expect(function() {
1889+
$httpBackend.flush();
1890+
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: hello.html');
18901891
expect(sortedHtml(element)).toBe('<div><b class="hello"></b></div>');
1891-
expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'tpload',
1892-
'Failed to load template: hello.html');
18931892
})
18941893
);
18951894

@@ -1905,13 +1904,13 @@ describe('$compile', function() {
19051904
templateUrl: 'template.html'
19061905
}));
19071906
});
1908-
inject(function($compile, $exceptionHandler, $httpBackend) {
1907+
inject(function($compile, $httpBackend) {
19091908
$httpBackend.whenGET('template.html').respond('<p>template.html</p>');
19101909

1911-
$compile('<div><div class="sync async"></div></div>');
1912-
$httpBackend.flush();
1913-
1914-
expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir',
1910+
expect(function() {
1911+
$compile('<div><div class="sync async"></div></div>');
1912+
$httpBackend.flush();
1913+
}).toThrowMinErr('$compile', 'multidir',
19151914
'Multiple directives [async, sync] asking for template on: ' +
19161915
'<div class="sync async">');
19171916
});
@@ -2122,15 +2121,15 @@ describe('$compile', function() {
21222121
'multiple root elements': '<div></div><div></div>'
21232122
}, function(directiveTemplate) {
21242123

2125-
inject(function($compile, $templateCache, $rootScope, $exceptionHandler) {
2124+
inject(function($compile, $templateCache, $rootScope) {
21262125
$templateCache.put('template.html', directiveTemplate);
2127-
$compile('<p template></p>')($rootScope);
2128-
$rootScope.$digest();
21292126

2130-
expect($exceptionHandler.errors.pop()).toEqualMinErr('$compile', 'tplrt',
2131-
'Template for directive \'template\' must have exactly one root element. ' +
2132-
'template.html'
2133-
);
2127+
expect(function() {
2128+
$compile('<p template></p>')($rootScope);
2129+
$rootScope.$digest();
2130+
}).toThrowMinErr('$compile', 'tplrt',
2131+
'Template for directive \'template\' must have exactly one root element. ' +
2132+
'template.html');
21342133
});
21352134
});
21362135

@@ -2657,13 +2656,13 @@ describe('$compile', function() {
26572656
);
26582657

26592658
it('should not allow more than one isolate/new scope creation per element regardless of `templateUrl`',
2660-
inject(function($exceptionHandler, $httpBackend) {
2659+
inject(function($httpBackend) {
26612660
$httpBackend.expect('GET', 'tiscope.html').respond('<div>Hello, world !</div>');
26622661

2663-
compile('<div class="tiscope-a; scope-b"></div>');
2664-
$httpBackend.flush();
2665-
2666-
expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir',
2662+
expect(function() {
2663+
compile('<div class="tiscope-a; scope-b"></div>');
2664+
$httpBackend.flush();
2665+
}).toThrowMinErr('$compile', 'multidir',
26672666
'Multiple directives [scopeB, tiscopeA] asking for new/isolated scope on: ' +
26682667
'<div class="tiscope-a; scope-b ng-scope">');
26692668
})
@@ -8997,18 +8996,17 @@ describe('$compile', function() {
89978996
}));
89988997
});
89998998

9000-
inject(function($compile, $exceptionHandler, $rootScope, $templateCache) {
8999+
inject(function($compile, $rootScope, $templateCache) {
90019000
$templateCache.put('noTransBar.html',
90029001
'<div>' +
90039002
// This ng-transclude is invalid. It should throw an error.
90049003
'<div class="bar" ng-transclude></div>' +
90059004
'</div>');
90069005

9007-
element = $compile('<div trans-foo>content</div>')($rootScope);
9008-
$rootScope.$digest();
9009-
9010-
expect($exceptionHandler.errors[0][1]).toBe('<div class="bar" ng-transclude="">');
9011-
expect($exceptionHandler.errors[0][0]).toEqualMinErr('ngTransclude', 'orphan',
9006+
expect(function() {
9007+
element = $compile('<div trans-foo>content</div>')($rootScope);
9008+
$rootScope.$digest();
9009+
}).toThrowMinErr('ngTransclude', 'orphan',
90129010
'Illegal use of ngTransclude directive in the template! ' +
90139011
'No parent directive that requires a transclusion found. ' +
90149012
'Element: <div class="bar" ng-transclude="">');
@@ -9821,13 +9819,13 @@ describe('$compile', function() {
98219819
transclude: 'element'
98229820
}));
98239821
});
9824-
inject(function($compile, $exceptionHandler, $httpBackend) {
9822+
inject(function($compile, $httpBackend) {
98259823
$httpBackend.expectGET('template.html').respond('<p second>template.html</p>');
98269824

9827-
$compile('<div template first></div>');
9828-
$httpBackend.flush();
9829-
9830-
expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir',
9825+
expect(function() {
9826+
$compile('<div template first></div>');
9827+
$httpBackend.flush();
9828+
}).toThrowMinErr('$compile', 'multidir',
98319829
'Multiple directives [first, second] asking for transclusion on: <p ');
98329830
});
98339831
});

0 commit comments

Comments
 (0)