fix(upgrade): fix `registerForNg1Tests` (#13522)
Fix an issue in `registerForNg1Tests`, where it passes a `null` as `ng1Injector` to `_bootstrapDone`. This causes a "TypeError: Cannot read property 'get' of null" to be thrown from `_bootstrapDone`.
This commit is contained in:
parent
55dfa1b69d
commit
c6e893953f
|
@ -24,17 +24,25 @@ module.exports = function(config) {
|
|||
'node_modules/core-js/client/core.js',
|
||||
// include Angular v1 for upgrade module testing
|
||||
'node_modules/angular/angular.js',
|
||||
'node_modules/angular-mocks/angular-mocks.js',
|
||||
|
||||
'node_modules/zone.js/dist/zone.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/zone.js/dist/proxy.js', 'node_modules/zone.js/dist/sync-test.js',
|
||||
'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/async-test.js',
|
||||
'node_modules/zone.js/dist/zone.js',
|
||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/zone.js/dist/proxy.js',
|
||||
'node_modules/zone.js/dist/sync-test.js',
|
||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
||||
'node_modules/zone.js/dist/async-test.js',
|
||||
'node_modules/zone.js/dist/fake-async-test.js',
|
||||
|
||||
// Including systemjs because it defines `__eval`, which produces correct stack traces.
|
||||
'shims_for_IE.js', 'node_modules/systemjs/dist/system.src.js',
|
||||
'shims_for_IE.js',
|
||||
'node_modules/systemjs/dist/system.src.js',
|
||||
{pattern: 'node_modules/rxjs/**', included: false, watched: false, served: true},
|
||||
'node_modules/reflect-metadata/Reflect.js', 'tools/build/file2modulename.js', 'test-main.js',
|
||||
{pattern: 'dist/all/empty.*', included: false, watched: false}, {
|
||||
'node_modules/reflect-metadata/Reflect.js',
|
||||
'tools/build/file2modulename.js',
|
||||
'test-main.js',
|
||||
{pattern: 'dist/all/empty.*', included: false, watched: false},
|
||||
{
|
||||
pattern: 'modules/@angular/platform-browser/test/static_assets/**',
|
||||
included: false,
|
||||
watched: false
|
||||
|
|
|
@ -320,7 +320,7 @@ export class UpgradeAdapter {
|
|||
windowNgMock.module(this.ng1Module.name);
|
||||
const upgrade = new UpgradeAdapterRef();
|
||||
this.ng2BootstrapDeferred.promise.then(
|
||||
() => { (<any>upgrade)._bootstrapDone(this.moduleRef, upgrade.ng1Injector); }, onError);
|
||||
(ng1Injector) => { (<any>upgrade)._bootstrapDone(this.moduleRef, ng1Injector); }, onError);
|
||||
return upgrade;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import {async, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
|||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import * as angular from '@angular/upgrade/src/angular_js';
|
||||
import {UpgradeAdapter, sortProjectableNodes} from '@angular/upgrade/src/upgrade_adapter';
|
||||
import {UpgradeAdapter, UpgradeAdapterRef, sortProjectableNodes} from '@angular/upgrade/src/upgrade_adapter';
|
||||
|
||||
export function main() {
|
||||
describe('adapter: ng1 to ng2', () => {
|
||||
|
@ -1296,6 +1296,44 @@ export function main() {
|
|||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('registerForNg1Tests', () => {
|
||||
let upgradeAdapterRef: UpgradeAdapterRef;
|
||||
let $compile: angular.ICompileService;
|
||||
let $rootScope: angular.IRootScopeService;
|
||||
|
||||
beforeEach(() => {
|
||||
const ng1Module = angular.module('ng1', []);
|
||||
|
||||
const Ng2 = Component({
|
||||
selector: 'ng2',
|
||||
template: 'Hello World',
|
||||
}).Class({constructor: function() {}});
|
||||
|
||||
const Ng2Module = NgModule({declarations: [Ng2], imports: [BrowserModule]}).Class({
|
||||
constructor: function() {}
|
||||
});
|
||||
|
||||
const upgradeAdapter = new UpgradeAdapter(Ng2Module);
|
||||
ng1Module.directive('ng2', upgradeAdapter.downgradeNg2Component(Ng2));
|
||||
|
||||
upgradeAdapterRef = upgradeAdapter.registerForNg1Tests(['ng1']);
|
||||
});
|
||||
|
||||
beforeEach(
|
||||
inject((_$compile_: angular.ICompileService, _$rootScope_: angular.IRootScopeService) => {
|
||||
$compile = _$compile_;
|
||||
$rootScope = _$rootScope_;
|
||||
}));
|
||||
|
||||
it('should be able to test ng1 components that use ng2 components', async(() => {
|
||||
upgradeAdapterRef.ready(() => {
|
||||
const element = $compile('<ng2></ng2>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element[0].textContent).toContain('Hello World');
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortProjectableNodes', () => {
|
||||
|
|
Loading…
Reference in New Issue