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

fix($compile): do not swallow thrown errors in test #15631

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (error instanceof Error) {
$exceptionHandler(error);
}
}).catch(noop);
});

return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {
var childBoundTranscludeFn = boundTranscludeFn;
Expand Down
64 changes: 31 additions & 33 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,15 +1881,14 @@ describe('$compile', function() {


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

$httpBackend.flush();

expect(function() {
$httpBackend.flush();
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: hello.html');
expect(sortedHtml(element)).toBe('<div><b class="hello"></b></div>');
expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'tpload',
'Failed to load template: hello.html');
})
);

Expand All @@ -1905,13 +1904,13 @@ describe('$compile', function() {
templateUrl: 'template.html'
}));
});
inject(function($compile, $exceptionHandler, $httpBackend) {
inject(function($compile, $httpBackend) {
$httpBackend.whenGET('template.html').respond('<p>template.html</p>');

$compile('<div><div class="sync async"></div></div>');
$httpBackend.flush();

expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir',
expect(function() {
$compile('<div><div class="sync async"></div></div>');
$httpBackend.flush();
}).toThrowMinErr('$compile', 'multidir',
'Multiple directives [async, sync] asking for template on: ' +
'<div class="sync async">');
});
Expand Down Expand Up @@ -2122,15 +2121,15 @@ describe('$compile', function() {
'multiple root elements': '<div></div><div></div>'
}, function(directiveTemplate) {

inject(function($compile, $templateCache, $rootScope, $exceptionHandler) {
inject(function($compile, $templateCache, $rootScope) {
$templateCache.put('template.html', directiveTemplate);
$compile('<p template></p>')($rootScope);
$rootScope.$digest();

expect($exceptionHandler.errors.pop()).toEqualMinErr('$compile', 'tplrt',
'Template for directive \'template\' must have exactly one root element. ' +
'template.html'
);
expect(function() {
$compile('<p template></p>')($rootScope);
$rootScope.$digest();
}).toThrowMinErr('$compile', 'tplrt',
'Template for directive \'template\' must have exactly one root element. ' +
'template.html');
});
});

Expand Down Expand Up @@ -2657,13 +2656,13 @@ describe('$compile', function() {
);

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

compile('<div class="tiscope-a; scope-b"></div>');
$httpBackend.flush();

expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir',
expect(function() {
compile('<div class="tiscope-a; scope-b"></div>');
$httpBackend.flush();
}).toThrowMinErr('$compile', 'multidir',
'Multiple directives [scopeB, tiscopeA] asking for new/isolated scope on: ' +
'<div class="tiscope-a; scope-b ng-scope">');
})
Expand Down Expand Up @@ -8997,18 +8996,17 @@ describe('$compile', function() {
}));
});

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

element = $compile('<div trans-foo>content</div>')($rootScope);
$rootScope.$digest();

expect($exceptionHandler.errors[0][1]).toBe('<div class="bar" ng-transclude="">');
expect($exceptionHandler.errors[0][0]).toEqualMinErr('ngTransclude', 'orphan',
expect(function() {
element = $compile('<div trans-foo>content</div>')($rootScope);
$rootScope.$digest();
}).toThrowMinErr('ngTransclude', 'orphan',
'Illegal use of ngTransclude directive in the template! ' +
'No parent directive that requires a transclusion found. ' +
'Element: <div class="bar" ng-transclude="">');
Expand Down Expand Up @@ -9821,13 +9819,13 @@ describe('$compile', function() {
transclude: 'element'
}));
});
inject(function($compile, $exceptionHandler, $httpBackend) {
inject(function($compile, $httpBackend) {
$httpBackend.expectGET('template.html').respond('<p second>template.html</p>');

$compile('<div template first></div>');
$httpBackend.flush();

expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir',
expect(function() {
$compile('<div template first></div>');
$httpBackend.flush();
}).toThrowMinErr('$compile', 'multidir',
'Multiple directives [first, second] asking for transclusion on: <p ');
});
});
Expand Down