Skip to content

Commit

Permalink
fix(upgrade): silent bootstrap failures
Browse files Browse the repository at this point in the history
fixes #12062
  • Loading branch information
btrigueiro authored and vsavkin committed Oct 27, 2016
1 parent f4be2f9 commit fa93fd6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/@angular/upgrade/src/upgrade_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ export class UpgradeAdapter {
});
})
.then(resolve, reject);
});
})
.catch(reject);
}
]);
});
Expand Down
45 changes: 44 additions & 1 deletion modules/@angular/upgrade/test/upgrade_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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: `<BAD TEMPLATE div></div>`}).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('<ng2></ng2>');
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('<ng2></ng2>');
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', []);

Expand Down

0 comments on commit fa93fd6

Please sign in to comment.