fix(upgrade): propagate return value of resumeBootstrap (#22754)

Fixes #22723

PR Close #22754
This commit is contained in:
Jason Bedard 2018-03-14 00:17:09 -07:00 committed by Alex Rickabaugh
parent ff34d5ea7a
commit a2330ff2db
4 changed files with 46 additions and 3 deletions

View File

@ -389,8 +389,9 @@ export class UpgradeAdapter {
const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
windowAngular.resumeBootstrap = function() {
windowAngular.resumeBootstrap = originalResumeBootstrap;
windowAngular.resumeBootstrap.apply(this, arguments);
const r = windowAngular.resumeBootstrap.apply(this, arguments);
resolve();
return r;
};
} else {
resolve();

View File

@ -268,7 +268,7 @@ export class UpgradeModule {
windowAngular.resumeBootstrap = function() {
let args = arguments;
windowAngular.resumeBootstrap = originalResumeBootstrap;
ngZone.run(() => { windowAngular.resumeBootstrap.apply(this, args); });
return ngZone.run(() => windowAngular.resumeBootstrap.apply(this, args));
};
}
}

View File

@ -2909,6 +2909,29 @@ withEachNg1Version(() => {
}, 100);
}));
it('should propagate return value of resumeBootstrap', fakeAsync(() => {
@NgModule({imports: [BrowserModule]})
class MyNg2Module {
}
const adapter: UpgradeAdapter = new UpgradeAdapter(MyNg2Module);
const ng1Module = angular.module('ng1', []);
let a1Injector: angular.IInjectorService|undefined;
ng1Module.run([
'$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; }
]);
const element = html('<div></div>');
window.name = 'NG_DEFER_BOOTSTRAP!' + window.name;
adapter.bootstrap(element, [ng1Module.name]).ready((ref) => { ref.dispose(); });
tick(100);
const value = (<any>window).angular.resumeBootstrap();
expect(value).toBe(a1Injector);
}));
it('should wait for ng2 testability', async(() => {
@NgModule({imports: [BrowserModule]})
class MyNg2Module {

View File

@ -8,7 +8,7 @@
import {NgModule, Testability, destroyPlatform} from '@angular/core';
import {NgZone} from '@angular/core/src/zone/ng_zone';
import {fakeAsync, tick} from '@angular/core/testing';
import {fakeAsync, flush, tick} from '@angular/core/testing';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {UpgradeModule} from '@angular/upgrade/static';
@ -48,6 +48,25 @@ withEachNg1Version(() => {
expect(stayedInTheZone).toEqual(true);
}));
it('should propagate return value of resumeBootstrap', fakeAsync(() => {
const ng1Module = angular.module('ng1', []);
let a1Injector: angular.IInjectorService|undefined;
ng1Module.run([
'$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; }
]);
const element = html('<div></div>');
window.name = 'NG_DEFER_BOOTSTRAP!' + window.name;
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module);
tick(100);
const value = (<any>window).angular.resumeBootstrap();
expect(value).toBe(a1Injector);
flush();
}));
it('should wait for ng2 testability', fakeAsync(() => {
const ng1Module = angular.module('ng1', []);
const element = html('<div></div>');