Skip to content

Commit fa93fd6

Browse files
btrigueirovsavkin
authored andcommitted
fix(upgrade): silent bootstrap failures
fixes angular#12062
1 parent f4be2f9 commit fa93fd6

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

modules/@angular/upgrade/src/upgrade_adapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ export class UpgradeAdapter {
418418
});
419419
})
420420
.then(resolve, reject);
421-
});
421+
})
422+
.catch(reject);
422423
}
423424
]);
424425
});

modules/@angular/upgrade/test/upgrade_spec.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Class, Component, EventEmitter, NO_ERRORS_SCHEMA, NgModule, Testability, destroyPlatform, forwardRef} from '@angular/core';
10-
import {async} from '@angular/core/testing';
10+
import {async, fakeAsync, flushMicrotasks} from '@angular/core/testing';
1111
import {BrowserModule} from '@angular/platform-browser';
1212
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
1313
import {UpgradeAdapter} from '@angular/upgrade';
@@ -20,6 +20,49 @@ export function main() {
2020

2121
it('should have angular 1 loaded', () => expect(angular.version.major).toBe(1));
2222

23+
describe('bootstrap errors', () => {
24+
let adapter: UpgradeAdapter;
25+
26+
beforeEach(() => {
27+
const ng1Module = angular.module('ng1', []);
28+
29+
const ng2Component =
30+
Component({selector: 'ng2', template: `<BAD TEMPLATE div></div>`}).Class({
31+
constructor: function() {}
32+
});
33+
34+
const Ng2Module = NgModule({declarations: [ng2Component], imports: [BrowserModule]}).Class({
35+
constructor: function() {}
36+
});
37+
38+
adapter = new UpgradeAdapter(Ng2Module);
39+
});
40+
41+
it('should throw an uncaught error', fakeAsync(() => {
42+
const element = html('<ng2></ng2>');
43+
const resolveSpy = jasmine.createSpy('resolveSpy');
44+
spyOn(console, 'log');
45+
46+
expect(() => {
47+
adapter.bootstrap(element, ['ng1']).ready(resolveSpy);
48+
flushMicrotasks();
49+
}).toThrowError();
50+
expect(resolveSpy).not.toHaveBeenCalled();
51+
}));
52+
53+
it('should properly log to the console and re throw', fakeAsync(() => {
54+
const element = html('<ng2></ng2>');
55+
spyOn(console, 'log');
56+
57+
expect(() => {
58+
adapter.bootstrap(element, ['ng1']);
59+
flushMicrotasks();
60+
}).toThrowError();
61+
expect(console.log).toHaveBeenCalled();
62+
expect(console.log).toHaveBeenCalledWith(jasmine.any(Error), jasmine.any(String));
63+
}));
64+
});
65+
2366
it('should instantiate ng2 in ng1 template and project content', async(() => {
2467
const ng1Module = angular.module('ng1', []);
2568

0 commit comments

Comments
 (0)