diff --git a/modules/@angular/upgrade/src/upgrade_adapter.ts b/modules/@angular/upgrade/src/upgrade_adapter.ts index 45f133eeb9..03d7ee8d18 100644 --- a/modules/@angular/upgrade/src/upgrade_adapter.ts +++ b/modules/@angular/upgrade/src/upgrade_adapter.ts @@ -418,7 +418,8 @@ export class UpgradeAdapter { }); }) .then(resolve, reject); - }); + }) + .catch(reject); } ]); }); diff --git a/modules/@angular/upgrade/test/upgrade_spec.ts b/modules/@angular/upgrade/test/upgrade_spec.ts index 9ff21974d2..8567148634 100644 --- a/modules/@angular/upgrade/test/upgrade_spec.ts +++ b/modules/@angular/upgrade/test/upgrade_spec.ts @@ -7,7 +7,7 @@ */ import {Class, Component, EventEmitter, NO_ERRORS_SCHEMA, NgModule, Testability, destroyPlatform, forwardRef} from '@angular/core'; -import {async} from '@angular/core/testing'; +import {async, fakeAsync, flushMicrotasks} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {UpgradeAdapter} from '@angular/upgrade'; @@ -20,6 +20,49 @@ export function main() { it('should have angular 1 loaded', () => expect(angular.version.major).toBe(1)); + describe('bootstrap errors', () => { + let adapter: UpgradeAdapter; + + beforeEach(() => { + const ng1Module = angular.module('ng1', []); + + const ng2Component = + Component({selector: 'ng2', template: ``}).Class({ + constructor: function() {} + }); + + const Ng2Module = NgModule({declarations: [ng2Component], imports: [BrowserModule]}).Class({ + constructor: function() {} + }); + + adapter = new UpgradeAdapter(Ng2Module); + }); + + it('should throw an uncaught error', fakeAsync(() => { + const element = html(''); + const resolveSpy = jasmine.createSpy('resolveSpy'); + spyOn(console, 'log'); + + expect(() => { + adapter.bootstrap(element, ['ng1']).ready(resolveSpy); + flushMicrotasks(); + }).toThrowError(); + expect(resolveSpy).not.toHaveBeenCalled(); + })); + + it('should properly log to the console and re throw', fakeAsync(() => { + const element = html(''); + spyOn(console, 'log'); + + expect(() => { + adapter.bootstrap(element, ['ng1']); + flushMicrotasks(); + }).toThrowError(); + expect(console.log).toHaveBeenCalled(); + expect(console.log).toHaveBeenCalledWith(jasmine.any(Error), jasmine.any(String)); + })); + }); + it('should instantiate ng2 in ng1 template and project content', async(() => { const ng1Module = angular.module('ng1', []);