77 */
88
99import { 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' ;
1111import { BrowserModule } from '@angular/platform-browser' ;
1212import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' ;
1313import { 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