|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -fdescribe('$compile', function() { |
| 3 | +describe('$compile', function() { |
4 | 4 | function isUnknownElement(el) {
|
5 | 5 | return !!el.toString().match(/Unknown/);
|
6 | 6 | }
|
@@ -3563,6 +3563,46 @@ fdescribe('$compile', function() {
|
3563 | 3563 | expect(Controller2.prototype.$onInit).toHaveBeenCalledOnce();
|
3564 | 3564 | });
|
3565 | 3565 | });
|
| 3566 | + |
| 3567 | + it('should continue to trigger other `$onInit` hooks if one throws an error', function() { |
| 3568 | + function ThrowingController() { |
| 3569 | + this.$onInit = function() { |
| 3570 | + throw new Error('bad hook'); |
| 3571 | + }; |
| 3572 | + } |
| 3573 | + function LoggingController($log) { |
| 3574 | + this.$onInit = function() { |
| 3575 | + $log.info('onInit'); |
| 3576 | + }; |
| 3577 | + } |
| 3578 | + |
| 3579 | + angular.module('my', []) |
| 3580 | + .component('c1', { |
| 3581 | + controller: ThrowingController, |
| 3582 | + bindings: {'prop': '<'} |
| 3583 | + }) |
| 3584 | + .component('c2', { |
| 3585 | + controller: LoggingController, |
| 3586 | + bindings: {'prop': '<'} |
| 3587 | + }) |
| 3588 | + .config(function($exceptionHandlerProvider) { |
| 3589 | + // We need to test with the exceptionHandler not rethrowing... |
| 3590 | + $exceptionHandlerProvider.mode('log'); |
| 3591 | + }); |
| 3592 | + |
| 3593 | + module('my'); |
| 3594 | + inject(function($compile, $rootScope, $exceptionHandler, $log) { |
| 3595 | + |
| 3596 | + // Setup the directive with bindings that will keep updating the bound value forever |
| 3597 | + element = $compile('<div><c1 prop="a"></c1><c2 prop="a"></c2>')($rootScope); |
| 3598 | + |
| 3599 | + // The first component's error should be logged |
| 3600 | + expect($exceptionHandler.errors.pop().toString()).toEqual('Error: bad hook'); |
| 3601 | + |
| 3602 | + // The second component's hook should still be called |
| 3603 | + expect($log.info.logs.pop()).toEqual(['onInit']); |
| 3604 | + }); |
| 3605 | + }); |
3566 | 3606 | });
|
3567 | 3607 |
|
3568 | 3608 |
|
@@ -4113,7 +4153,9 @@ fdescribe('$compile', function() {
|
4113 | 4153 | $rootScope.$apply('a = 42');
|
4114 | 4154 |
|
4115 | 4155 | // Both component's error should be logged
|
4116 |
| - expect($exceptionHandler.errors[0]).toEqual([new Error('bad hook: 42'), new Error('bad hook: 84')]); |
| 4156 | + var errors = $exceptionHandler.errors.pop(); |
| 4157 | + expect(errors.pop()).toEqual(new Error('bad hook: 84')); |
| 4158 | + expect(errors.pop()).toEqual(new Error('bad hook: 42')); |
4117 | 4159 | });
|
4118 | 4160 | });
|
4119 | 4161 | });
|
|
0 commit comments