fix(zone.js): add issue numbers of @types/jasmine
to the test cases (#34625)
Some cases will still need to use `spy as any` cast, because `@types/jasmine` have some issues, 1. The issue jasmine doesn't handle optional method properties, https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486 2. The issue jasmine doesn't handle overload method correctly, https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455 PR Close #34625
This commit is contained in:

committed by
Kara Erickson

parent
b28a5f6eef
commit
421b6a97d6
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef, Component, EventEmitter, Input, NO_ERRORS_SCHEMA, NgModule, NgModuleFactory, NgZone, OnChanges, OnDestroy, Output, SimpleChange, SimpleChanges, Testability, destroyPlatform, forwardRef} from '@angular/core';
|
||||
import {ChangeDetectorRef, Component, destroyPlatform, EventEmitter, forwardRef, Input, NgModule, NgModuleFactory, NgZone, NO_ERRORS_SCHEMA, OnChanges, OnDestroy, Output, SimpleChange, SimpleChanges, Testability} from '@angular/core';
|
||||
import {async, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
@ -23,7 +23,6 @@ declare global {
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('adapter: ng1 to ng2', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
@ -232,7 +231,9 @@ withEachNg1Version(() => {
|
||||
})
|
||||
class Ng2 {
|
||||
l: any;
|
||||
constructor() { this.l = l; }
|
||||
constructor() {
|
||||
this.l = l;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -262,7 +263,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'my-app', template: '<my-child [value]="value"></my-child>'})
|
||||
class AppComponent {
|
||||
value?: number;
|
||||
constructor() { appComponent = this; }
|
||||
constructor() {
|
||||
appComponent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -272,7 +275,9 @@ withEachNg1Version(() => {
|
||||
class ChildComponent {
|
||||
valueFromPromise?: number;
|
||||
@Input()
|
||||
set value(v: number) { expect(NgZone.isInAngularZone()).toBe(true); }
|
||||
set value(v: number) {
|
||||
expect(NgZone.isInAngularZone()).toBe(true);
|
||||
}
|
||||
|
||||
constructor(private zone: NgZone) {}
|
||||
|
||||
@ -352,14 +357,15 @@ withEachNg1Version(() => {
|
||||
|
||||
const element = html('<ng2></ng2>');
|
||||
adapter.bootstrap(element, ['ng1']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent !)).toBe('It works');
|
||||
expect(multiTrim(document.body.textContent!)).toBe('It works');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should bind properties, events', async(() => {
|
||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module =
|
||||
angular.module_('ng1', []).value($EXCEPTION_HANDLER, (err: any) => { throw err; });
|
||||
const ng1Module = angular.module_('ng1', []).value($EXCEPTION_HANDLER, (err: any) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
ng1Module.run(($rootScope: any) => {
|
||||
$rootScope.name = 'world';
|
||||
@ -409,8 +415,8 @@ withEachNg1Version(() => {
|
||||
}
|
||||
const actValue = changes[prop].currentValue;
|
||||
if (actValue != value) {
|
||||
throw new Error(
|
||||
`Expected changes record for'${prop}' to be '${value}' but was '${actValue}'`);
|
||||
throw new Error(`Expected changes record for'${prop}' to be '${
|
||||
value}' but was '${actValue}'`);
|
||||
}
|
||||
};
|
||||
|
||||
@ -458,7 +464,7 @@ withEachNg1Version(() => {
|
||||
| modelA: {{modelA}}; modelB: {{modelB}}; eventA: {{eventA}}; eventB: {{eventB}};
|
||||
</div>`);
|
||||
adapter.bootstrap(element, ['ng1']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent !))
|
||||
expect(multiTrim(document.body.textContent!))
|
||||
.toEqual(
|
||||
'ignore: -; ' +
|
||||
'literal: Text; interpolate: Hello world; ' +
|
||||
@ -466,7 +472,7 @@ withEachNg1Version(() => {
|
||||
'modelA: newA; modelB: newB; eventA: aFired; eventB: bFired;');
|
||||
|
||||
ref.ng1RootScope.$apply('name = "everyone"');
|
||||
expect(multiTrim(document.body.textContent !))
|
||||
expect(multiTrim(document.body.textContent!))
|
||||
.toEqual(
|
||||
'ignore: -; ' +
|
||||
'literal: Text; interpolate: Hello everyone; ' +
|
||||
@ -475,7 +481,6 @@ withEachNg1Version(() => {
|
||||
|
||||
ref.dispose();
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should support two-way binding and event listener', async(() => {
|
||||
@ -541,9 +546,9 @@ withEachNg1Version(() => {
|
||||
ngOnChangesCount = 0;
|
||||
firstChangesCount = 0;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
initialValue !: string;
|
||||
initialValue!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() foo !: string;
|
||||
@Input() foo!: string;
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
this.ngOnChangesCount++;
|
||||
@ -590,7 +595,9 @@ withEachNg1Version(() => {
|
||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
ng1Module.run(($rootScope: any /** TODO #9100 */) => { $rootScope.modelA = 'A'; });
|
||||
ng1Module.run(($rootScope: any /** TODO #9100 */) => {
|
||||
$rootScope.modelA = 'A';
|
||||
});
|
||||
|
||||
let ng2Instance: Ng2;
|
||||
@Component({selector: 'ng2', template: '{{_value}}'})
|
||||
@ -598,11 +605,21 @@ withEachNg1Version(() => {
|
||||
private _value: any = '';
|
||||
private _onChangeCallback: (_: any) => void = () => {};
|
||||
private _onTouchedCallback: () => void = () => {};
|
||||
constructor() { ng2Instance = this; }
|
||||
writeValue(value: any) { this._value = value; }
|
||||
registerOnChange(fn: any) { this._onChangeCallback = fn; }
|
||||
registerOnTouched(fn: any) { this._onTouchedCallback = fn; }
|
||||
doTouch() { this._onTouchedCallback(); }
|
||||
constructor() {
|
||||
ng2Instance = this;
|
||||
}
|
||||
writeValue(value: any) {
|
||||
this._value = value;
|
||||
}
|
||||
registerOnChange(fn: any) {
|
||||
this._onChangeCallback = fn;
|
||||
}
|
||||
registerOnTouched(fn: any) {
|
||||
this._onTouchedCallback = fn;
|
||||
}
|
||||
doTouch() {
|
||||
this._onTouchedCallback();
|
||||
}
|
||||
doChange(newValue: string) {
|
||||
this._value = newValue;
|
||||
this._onChangeCallback(newValue);
|
||||
@ -653,14 +670,18 @@ withEachNg1Version(() => {
|
||||
return {
|
||||
template: '<div ng-if="!destroyIt"><ng2></ng2></div>',
|
||||
controller: function($rootScope: any, $timeout: Function) {
|
||||
$timeout(() => { $rootScope.destroyIt = true; });
|
||||
$timeout(() => {
|
||||
$rootScope.destroyIt = true;
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@Component({selector: 'ng2', template: 'test'})
|
||||
class Ng2 {
|
||||
ngOnDestroy() { onDestroyed.emit('destroyed'); }
|
||||
ngOnDestroy() {
|
||||
onDestroyed.emit('destroyed');
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -673,7 +694,9 @@ withEachNg1Version(() => {
|
||||
ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2));
|
||||
const element = html('<ng1></ng1>');
|
||||
adapter.bootstrap(element, ['ng1']).ready((ref) => {
|
||||
onDestroyed.subscribe(() => { ref.dispose(); });
|
||||
onDestroyed.subscribe(() => {
|
||||
ref.dispose();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
@ -689,7 +712,9 @@ withEachNg1Version(() => {
|
||||
|
||||
@Component({selector: 'ng2-inner', template: 'test'})
|
||||
class Ng2InnerComponent implements OnDestroy {
|
||||
ngOnDestroy() { destroyed = true; }
|
||||
ngOnDestroy() {
|
||||
destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -789,7 +814,7 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: 'ng2-{{ itemId }}(<ng-content></ng-content>)'})
|
||||
class Ng2Component {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() itemId !: string;
|
||||
@Input() itemId!: string;
|
||||
}
|
||||
|
||||
@NgModule({imports: [BrowserModule], declarations: [Ng2Component]})
|
||||
@ -838,7 +863,7 @@ withEachNg1Version(() => {
|
||||
ng1Module.directive('rootComponent', adapter.downgradeNg2Component(RootComponent));
|
||||
|
||||
document.body.innerHTML = '<root-component></root-component>';
|
||||
adapter.bootstrap(document.body.firstElementChild !, ['myExample']).ready((ref) => {
|
||||
adapter.bootstrap(document.body.firstElementChild!, ['myExample']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent)).toEqual('It works!');
|
||||
ref.dispose();
|
||||
});
|
||||
@ -868,7 +893,9 @@ withEachNg1Version(() => {
|
||||
dataA = 'foo';
|
||||
dataB = 'bar';
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -888,8 +915,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
@ -932,7 +959,9 @@ withEachNg1Version(() => {
|
||||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -952,8 +981,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
@ -996,7 +1025,9 @@ withEachNg1Version(() => {
|
||||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -1016,8 +1047,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
@ -1077,8 +1108,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: - | Outside: foo, bar');
|
||||
|
||||
@ -1204,7 +1235,9 @@ withEachNg1Version(() => {
|
||||
restrict: 'E',
|
||||
template: '{{someText}} - Length: {{data.length}}',
|
||||
scope: {data: '='},
|
||||
controller: function($scope: any) { $scope.someText = 'ng1 - Data: ' + $scope.data; }
|
||||
controller: function($scope: any) {
|
||||
$scope.someText = 'ng1 - Data: ' + $scope.data;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -1248,7 +1281,9 @@ withEachNg1Version(() => {
|
||||
restrict: 'E',
|
||||
template: '{{someText}} - Length: {{data.length}}',
|
||||
scope: {data: '='},
|
||||
link: function($scope: any) { $scope.someText = 'ng1 - Data: ' + $scope.data; }
|
||||
link: function($scope: any) {
|
||||
$scope.someText = 'ng1 - Data: ' + $scope.data;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -1291,7 +1326,9 @@ withEachNg1Version(() => {
|
||||
cbFn(200, `${method}:${url}`);
|
||||
});
|
||||
|
||||
const ng1 = () => { return {templateUrl: 'url.html'}; };
|
||||
const ng1 = () => {
|
||||
return {templateUrl: 'url.html'};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
class Ng2 {
|
||||
@ -1320,7 +1357,13 @@ withEachNg1Version(() => {
|
||||
cbFn(200, `${method}:${url}`);
|
||||
});
|
||||
|
||||
const ng1 = () => { return {templateUrl() { return 'url.html'; }}; };
|
||||
const ng1 = () => {
|
||||
return {
|
||||
templateUrl() {
|
||||
return 'url.html';
|
||||
}
|
||||
};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
class Ng2 {
|
||||
@ -1345,7 +1388,9 @@ withEachNg1Version(() => {
|
||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
const ng1 = () => { return {template: ''}; };
|
||||
const ng1 = () => {
|
||||
return {template: ''};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
@ -1371,7 +1416,13 @@ withEachNg1Version(() => {
|
||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
const ng1 = () => { return {template() { return ''; }}; };
|
||||
const ng1 = () => {
|
||||
return {
|
||||
template() {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
@ -1398,7 +1449,9 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
ng1Module.run(($templateCache: any) => $templateCache.put('url.html', 'WORKS'));
|
||||
|
||||
const ng1 = () => { return {templateUrl: 'url.html'}; };
|
||||
const ng1 = () => {
|
||||
return {templateUrl: 'url.html'};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
@ -1431,13 +1484,20 @@ withEachNg1Version(() => {
|
||||
'{{ctl.scope}}; {{ctl.isClass}}; {{ctl.hasElement}}; {{ctl.isPublished()}}',
|
||||
controllerAs: 'ctl',
|
||||
controller: class {
|
||||
scope: any; hasElement: string; $element: any; isClass: any;
|
||||
scope: any;
|
||||
hasElement: string;
|
||||
$element: any;
|
||||
isClass: any;
|
||||
constructor($scope: any, $element: any) {
|
||||
this.verifyIAmAClass();
|
||||
this.scope = $scope.$parent.$parent == $scope.$root ? 'scope' : 'wrong-scope';
|
||||
this.hasElement = $element[0].nodeName;
|
||||
this.$element = $element;
|
||||
} verifyIAmAClass() { this.isClass = 'isClass'; } isPublished() {
|
||||
}
|
||||
verifyIAmAClass() {
|
||||
this.isClass = 'isClass';
|
||||
}
|
||||
isPublished() {
|
||||
return this.$element.controller('ng1') == this ? 'published' : 'not-published';
|
||||
}
|
||||
}
|
||||
@ -1543,7 +1603,9 @@ withEachNg1Version(() => {
|
||||
template: '{{ctl.status}}',
|
||||
require: 'ng1',
|
||||
controllerAs: 'ctrl',
|
||||
controller: class {status = 'WORKS';},
|
||||
controller: class {
|
||||
status = 'WORKS';
|
||||
},
|
||||
link: function(scope: any, element: any, attrs: any, linkController: any) {
|
||||
expect(scope.$root).toEqual($rootScope);
|
||||
expect(element[0].nodeName).toEqual('NG1');
|
||||
@ -1577,7 +1639,13 @@ withEachNg1Version(() => {
|
||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
const parent = () => { return {controller: class {parent = 'PARENT';}}; };
|
||||
const parent = () => {
|
||||
return {
|
||||
controller: class {
|
||||
parent = 'PARENT';
|
||||
}
|
||||
};
|
||||
};
|
||||
const ng1 = () => {
|
||||
return {
|
||||
scope: {title: '@'},
|
||||
@ -1585,7 +1653,9 @@ withEachNg1Version(() => {
|
||||
template: '{{parent.parent}}:{{ng1.status}}',
|
||||
require: ['ng1', '^parent', '?^^notFound'],
|
||||
controllerAs: 'ctrl',
|
||||
controller: class {status = 'WORKS';},
|
||||
controller: class {
|
||||
status = 'WORKS';
|
||||
},
|
||||
link: function(scope: any, element: any, attrs: any, linkControllers: any) {
|
||||
expect(linkControllers[0].status).toEqual('WORKS');
|
||||
expect(linkControllers[1].parent).toEqual('PARENT');
|
||||
@ -1633,16 +1703,21 @@ withEachNg1Version(() => {
|
||||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$onInit() { $onInitSpyA(); }}
|
||||
controller: class {
|
||||
$onInit() {
|
||||
$onInitSpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$onInit = $onInitSpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$onInit = $onInitSpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
@ -1718,7 +1793,9 @@ withEachNg1Version(() => {
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1-a></ng1-a> | <ng1-b></ng1-b>'})
|
||||
class Ng2Component {
|
||||
constructor(cd: ChangeDetectorRef) { changeDetector = cd; }
|
||||
constructor(cd: ChangeDetectorRef) {
|
||||
changeDetector = cd;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module_('ng1', [])
|
||||
@ -1727,16 +1804,21 @@ withEachNg1Version(() => {
|
||||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$doCheck() { $doCheckSpyA(); }}
|
||||
controller: class {
|
||||
$doCheck() {
|
||||
$doCheckSpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$doCheck = $doCheckSpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$doCheck = $doCheckSpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
@ -1773,7 +1855,9 @@ withEachNg1Version(() => {
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1-a></ng1-a> | <ng1-b></ng1-b>'})
|
||||
class Ng2Component {
|
||||
constructor(cd: ChangeDetectorRef) { changeDetector = cd; }
|
||||
constructor(cd: ChangeDetectorRef) {
|
||||
changeDetector = cd;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module_('ng1', [])
|
||||
@ -1835,16 +1919,21 @@ withEachNg1Version(() => {
|
||||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$postLink() { $postLinkSpyA(); }}
|
||||
controller: class {
|
||||
$postLink() {
|
||||
$postLinkSpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$postLink = $postLinkSpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$postLink = $postLinkSpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
@ -1924,7 +2013,9 @@ withEachNg1Version(() => {
|
||||
template: '<ng1-a [valA]="val"></ng1-a> | <ng1-b [valB]="val"></ng1-b>'
|
||||
})
|
||||
class Ng2Component {
|
||||
constructor() { ng2Instance = this; }
|
||||
constructor() {
|
||||
ng2Instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module_('ng1', [])
|
||||
@ -1937,17 +2028,17 @@ withEachNg1Version(() => {
|
||||
this.$onChanges = $onChangesControllerSpyA;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B',
|
||||
() => ({
|
||||
template: '',
|
||||
scope: {valB: '<'},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {
|
||||
$onChanges(changes: SimpleChanges) { $onChangesControllerSpyB(changes); }
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {valB: '<'},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {
|
||||
$onChanges(changes: SimpleChanges) {
|
||||
$onChangesControllerSpyB(changes);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component))
|
||||
.run(($rootScope: angular.IRootScopeService) => {
|
||||
Object.getPrototypeOf($rootScope).$onChanges = $onChangesScopeSpy;
|
||||
@ -2022,7 +2113,9 @@ withEachNg1Version(() => {
|
||||
})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
@ -2036,16 +2129,21 @@ withEachNg1Version(() => {
|
||||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$onDestroy() { $onDestroySpyA(); }}
|
||||
controller: class {
|
||||
$onDestroy() {
|
||||
$onDestroySpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$onDestroy = $onDestroySpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$onDestroy = $onDestroySpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
@ -2112,7 +2210,9 @@ withEachNg1Version(() => {
|
||||
})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
@ -2187,7 +2287,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: '<div *ngIf="!ng2Destroy"><ng1></ng1></div>'})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
@ -2233,7 +2335,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: '<div *ngIf="!ng2Destroy"><ng1></ng1></div>'})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
@ -2245,8 +2349,8 @@ withEachNg1Version(() => {
|
||||
.component('ng1', {
|
||||
controller: class {
|
||||
constructor(private $element: angular.IAugmentedJQuery) {} $onInit() {
|
||||
this.$element.on !('$destroy', elementDestroyListener);
|
||||
this.$element.contents !().on !('$destroy', descendantDestroyListener);
|
||||
this.$element.on!('$destroy', elementDestroyListener);
|
||||
this.$element.contents!().on!('$destroy', descendantDestroyListener);
|
||||
}
|
||||
},
|
||||
template: '<div></div>'
|
||||
@ -2287,8 +2391,8 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor(private $element: angular.IAugmentedJQuery) {} $onInit() {
|
||||
this.$element.data !('test', 1);
|
||||
this.$element.contents !().data !('test', 2);
|
||||
this.$element.data!('test', 1);
|
||||
this.$element.contents!().data!('test', 2);
|
||||
|
||||
ng1ComponentElement = this.$element;
|
||||
}
|
||||
@ -2301,7 +2405,9 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
@ -2330,15 +2436,15 @@ withEachNg1Version(() => {
|
||||
const $rootScope = ref.ng1RootScope as any;
|
||||
tick();
|
||||
$rootScope.$digest();
|
||||
expect(ng1ComponentElement.data !('test')).toBe(1);
|
||||
expect(ng1ComponentElement.contents !().data !('test')).toBe(2);
|
||||
expect(ng1ComponentElement.data!('test')).toBe(1);
|
||||
expect(ng1ComponentElement.contents!().data!('test')).toBe(2);
|
||||
|
||||
ng2ComponentAInstance.destroyIt = true;
|
||||
tick();
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(ng1ComponentElement.data !('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.contents !().data !('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.data!('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.contents!().data!('test')).toBeUndefined();
|
||||
});
|
||||
}));
|
||||
|
||||
@ -2353,10 +2459,10 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor(private $element: angular.IAugmentedJQuery) {} $onInit() {
|
||||
ng1DescendantElement = this.$element.contents !();
|
||||
ng1DescendantElement = this.$element.contents!();
|
||||
|
||||
this.$element.on !('click', elementClickListener);
|
||||
ng1DescendantElement.on !('click', descendantClickListener);
|
||||
this.$element.on!('click', elementClickListener);
|
||||
ng1DescendantElement.on!('click', descendantClickListener);
|
||||
}
|
||||
},
|
||||
template: '<div></div>'
|
||||
@ -2367,7 +2473,9 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
@ -2420,7 +2528,11 @@ withEachNg1Version(() => {
|
||||
const ng1Directive: angular.IDirective = {
|
||||
template: '',
|
||||
link: {pre: () => log.push('ng1-pre')},
|
||||
controller: class {constructor() { log.push('ng1-ctrl'); }}
|
||||
controller: class {
|
||||
constructor() {
|
||||
log.push('ng1-ctrl');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng2Component`
|
||||
@ -2577,7 +2689,11 @@ withEachNg1Version(() => {
|
||||
const ng1Directive: angular.IDirective = {
|
||||
template: '',
|
||||
link: () => log.push('ng1-post'),
|
||||
controller: class {$postLink() { log.push('ng1-$post'); }}
|
||||
controller: class {
|
||||
$postLink() {
|
||||
log.push('ng1-$post');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng2Component`
|
||||
@ -2627,13 +2743,17 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
value = 'foo';
|
||||
showB = false;
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: 'ng2B({{ value }})'})
|
||||
class Ng2ComponentB {
|
||||
value = 'bar';
|
||||
constructor() { ng2ComponentBInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentBInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2678,7 +2798,10 @@ withEachNg1Version(() => {
|
||||
template: 'ng1(<div ng-transclude>{{ $ctrl.value }}</div>)',
|
||||
transclude: true,
|
||||
controller: class {
|
||||
value = 'from-ng1'; constructor() { ng1ControllerInstances.push(this); }
|
||||
value = 'from-ng1';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -2697,7 +2820,9 @@ withEachNg1Version(() => {
|
||||
})
|
||||
class Ng2Component {
|
||||
value = 'from-ng2';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2756,7 +2881,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2798,8 +2925,12 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
template: 'ng1(default(<div ng-transclude="">fallback-{{ $ctrl.value }}</div>))',
|
||||
transclude: {slotX: 'contentX', slotY: 'contentY'},
|
||||
controller:
|
||||
class {value = 'ng1'; constructor() { ng1ControllerInstances.push(this); }}
|
||||
controller: class {
|
||||
value = 'ng1';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng2Component`
|
||||
@ -2830,7 +2961,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2880,7 +3013,11 @@ withEachNg1Version(() => {
|
||||
)`,
|
||||
transclude: {slotX: '?contentX', slotY: '?contentY'},
|
||||
controller: class {
|
||||
x = 'ng1X'; y = 'ng1Y'; constructor() { ng1ControllerInstances.push(this); }
|
||||
x = 'ng1X';
|
||||
y = 'ng1Y';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -2896,7 +3033,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
x = 'ng2X';
|
||||
y = 'ng2Y';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -3000,7 +3139,9 @@ withEachNg1Version(() => {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
show = true;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -3202,13 +3343,18 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
let a1Injector: angular.IInjectorService|undefined;
|
||||
ng1Module.run([
|
||||
'$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; }
|
||||
'$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(); });
|
||||
adapter.bootstrap(element, [ng1Module.name]).ready((ref) => {
|
||||
ref.dispose();
|
||||
});
|
||||
|
||||
tick(100);
|
||||
|
||||
@ -3275,7 +3421,7 @@ withEachNg1Version(() => {
|
||||
|
||||
document.body.innerHTML = '<ng2 name="World">project</ng2>';
|
||||
|
||||
adapter.bootstrap(document.body.firstElementChild !, ['myExample']).ready((ref) => {
|
||||
adapter.bootstrap(document.body.firstElementChild!, ['myExample']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent))
|
||||
.toEqual('ng2[ng1[Hello World!](transclude)](project)');
|
||||
ref.dispose();
|
||||
|
Reference in New Issue
Block a user