refactor(core): type ComponentRef
, ComponentFactory
and ComponentFixture
by the component type
BREAKING CHANGE: - `ComponetRef`, `ComponentFactory`, `ComponentFixture` now all require a type parameter with the component type. Closes #8361
This commit is contained in:
@ -50,7 +50,7 @@ export function main() {
|
||||
describe("bootstrap", () => {
|
||||
var platform: PlatformRef;
|
||||
var errorLogger: _ArrayLogger;
|
||||
var someCompFactory: ComponentFactory;
|
||||
var someCompFactory: ComponentFactory<any>;
|
||||
|
||||
beforeEach(() => {
|
||||
errorLogger = new _ArrayLogger();
|
||||
@ -153,24 +153,24 @@ class _ArrayLogger {
|
||||
logGroupEnd(){};
|
||||
}
|
||||
|
||||
class _MockComponentFactory extends ComponentFactory {
|
||||
constructor(private _compRef: ComponentRef) { super(null, null, null); }
|
||||
class _MockComponentFactory extends ComponentFactory<any> {
|
||||
constructor(private _compRef: ComponentRef<any>) { super(null, null, null); }
|
||||
create(injector: Injector, projectableNodes: any[][] = null,
|
||||
rootSelectorOrNode: string | any = null): ComponentRef {
|
||||
rootSelectorOrNode: string | any = null): ComponentRef<any> {
|
||||
return this._compRef;
|
||||
}
|
||||
}
|
||||
|
||||
class _MockComponentResolver implements ComponentResolver {
|
||||
constructor(private _compFactory: ComponentFactory) {}
|
||||
constructor(private _compFactory: ComponentFactory<any>) {}
|
||||
|
||||
resolveComponent(type: Type): Promise<ComponentFactory> {
|
||||
resolveComponent(type: Type): Promise<ComponentFactory<any>> {
|
||||
return PromiseWrapper.resolve(this._compFactory);
|
||||
}
|
||||
clearCache() {}
|
||||
}
|
||||
|
||||
class _MockComponentRef extends ComponentRef_ {
|
||||
class _MockComponentRef extends ComponentRef_<any> {
|
||||
constructor(private _injector: Injector) { super(null, null); }
|
||||
get injector(): Injector { return this._injector; }
|
||||
get changeDetectorRef(): ChangeDetectorRef { return <any>new SpyChangeDetectorRef(); }
|
||||
|
@ -82,7 +82,7 @@ export function main() {
|
||||
var directiveLog: DirectiveLog;
|
||||
|
||||
function createCompFixture(template: string, compType: Type = TestComponent,
|
||||
_tcb: TestComponentBuilder = null): ComponentFixture {
|
||||
_tcb: TestComponentBuilder = null): ComponentFixture<any> {
|
||||
if (isBlank(_tcb)) {
|
||||
_tcb = tcb;
|
||||
}
|
||||
@ -98,12 +98,14 @@ export function main() {
|
||||
return nodes.map(node => node.inject(dirType));
|
||||
}
|
||||
|
||||
function _bindSimpleProp(bindAttr: string, compType: Type = TestComponent): ComponentFixture {
|
||||
function _bindSimpleProp(bindAttr: string,
|
||||
compType: Type = TestComponent): ComponentFixture<any> {
|
||||
var template = `<div ${bindAttr}></div>`;
|
||||
return createCompFixture(template, compType);
|
||||
}
|
||||
|
||||
function _bindSimpleValue(expression: any, compType: Type = TestComponent): ComponentFixture {
|
||||
function _bindSimpleValue(expression: any,
|
||||
compType: Type = TestComponent): ComponentFixture<any> {
|
||||
return _bindSimpleProp(`[someProp]='${expression}'`, compType);
|
||||
}
|
||||
|
||||
@ -640,7 +642,7 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('lifecycle', () => {
|
||||
function createCompWithContentAndViewChild(): ComponentFixture {
|
||||
function createCompWithContentAndViewChild(): ComponentFixture<any> {
|
||||
return createCompFixture(
|
||||
'<div testDirective="parent"><div *ngIf="true" testDirective="contentChild"></div><other-cmp></other-cmp></div>',
|
||||
TestComponent,
|
||||
|
@ -94,7 +94,7 @@ export function main() {
|
||||
it('should leave the view tree in a consistent state if hydration fails',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.createAsync(MyComp).then((tc: ComponentFixture) => {
|
||||
tcb.createAsync(MyComp).then((tc: ComponentFixture<any>) => {
|
||||
tc.detectChanges();
|
||||
PromiseWrapper.catchError(
|
||||
loader.loadNextToLocation(DynamicallyLoadedThrows,
|
||||
@ -146,7 +146,7 @@ export function main() {
|
||||
DOM.appendChild(doc.body, rootEl);
|
||||
loader.loadAsRoot(ChildComp, null, injector)
|
||||
.then((componentRef) => {
|
||||
var el = new ComponentFixture(componentRef, null, false);
|
||||
var el = new ComponentFixture<any>(componentRef, null, false);
|
||||
|
||||
expect(rootEl.parentNode).toBe(doc.body);
|
||||
|
||||
|
@ -770,14 +770,13 @@ function declareTests(isJit: boolean) {
|
||||
it("should allow to destroy a component from within a host event handler",
|
||||
fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
|
||||
var fixture: ComponentFixture;
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<push-cmp-with-host-event></push-cmp-with-host-event>',
|
||||
directives: [[[PushCmpWithHostEvent]]]
|
||||
}))
|
||||
|
||||
.createAsync(MyComp)
|
||||
.then(root => { fixture = root; });
|
||||
let fixture =
|
||||
tcb.overrideView(
|
||||
MyComp, new ViewMetadata({
|
||||
template: '<push-cmp-with-host-event></push-cmp-with-host-event>',
|
||||
directives: [[[PushCmpWithHostEvent]]]
|
||||
}))
|
||||
.createFakeAsync(MyComp);
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -865,8 +864,7 @@ function declareTests(isJit: boolean) {
|
||||
directives: [[[PushCmpWithAsyncPipe]]]
|
||||
}));
|
||||
|
||||
var fixture: ComponentFixture;
|
||||
tcb.createAsync(MyComp).then(root => { fixture = root; });
|
||||
let fixture = tcb.createFakeAsync(MyComp);
|
||||
tick();
|
||||
|
||||
var cmp: PushCmpWithAsyncPipe = fixture.debugElement.children[0].references['cmp'];
|
||||
@ -1500,8 +1498,7 @@ function declareTests(isJit: boolean) {
|
||||
directives: [DirectiveEmittingEvent, DirectiveListeningEvent]
|
||||
}));
|
||||
|
||||
var fixture: ComponentFixture;
|
||||
tcb.createAsync(MyComp).then(root => { fixture = root; });
|
||||
let fixture = tcb.createFakeAsync(MyComp);
|
||||
tick();
|
||||
|
||||
var tc = fixture.debugElement.children[0];
|
||||
@ -1606,7 +1603,7 @@ function declareTests(isJit: boolean) {
|
||||
directives: [SomeImperativeViewport]
|
||||
}))
|
||||
.createAsync(MyComp)
|
||||
.then((fixture: ComponentFixture) => {
|
||||
.then((fixture: ComponentFixture<any>) => {
|
||||
fixture.detectChanges();
|
||||
expect(anchorElement).toHaveText('');
|
||||
|
||||
@ -1828,8 +1825,7 @@ function declareTests(isJit: boolean) {
|
||||
directives: [DirectiveWithPropDecorators]
|
||||
}));
|
||||
|
||||
var fixture: ComponentFixture;
|
||||
tcb.createAsync(MyComp).then(root => { fixture = root; });
|
||||
let fixture = tcb.createFakeAsync(MyComp);
|
||||
tick();
|
||||
|
||||
var emitter = fixture.debugElement.children[0].inject(DirectiveWithPropDecorators);
|
||||
|
@ -293,7 +293,7 @@ export function main() {
|
||||
{template: '<simple stringProp="text"></simple>', directives: [Simple]}))
|
||||
.overrideTemplate(Simple, '<ng-content></ng-content><p>P,</p>{{stringProp}}')
|
||||
.createAsync(MainComp)
|
||||
.then((main: ComponentFixture) => {
|
||||
.then((main: ComponentFixture<any>) => {
|
||||
|
||||
main.detectChanges();
|
||||
|
||||
@ -314,7 +314,7 @@ export function main() {
|
||||
{template: '<simple stringProp="text"></simple>', directives: [Simple]}))
|
||||
.overrideTemplate(Simple, '<style></style><p>P,</p>{{stringProp}}')
|
||||
.createAsync(MainComp)
|
||||
.then((main: ComponentFixture) => {
|
||||
.then((main: ComponentFixture<any>) => {
|
||||
|
||||
main.detectChanges();
|
||||
expect(main.debugElement.nativeElement).toHaveText('P,text');
|
||||
|
@ -35,7 +35,7 @@ export function main() {
|
||||
it('should read the template from an annotation',
|
||||
inject([AsyncTestCompleter, ComponentResolver], (async, compiler: ComponentResolver) => {
|
||||
compiler.resolveComponent(SomeComponent)
|
||||
.then((compFactory: ComponentFactory) => {
|
||||
.then((compFactory: ComponentFactory<any>) => {
|
||||
expect(compFactory).toBe(someCompFactory);
|
||||
async.done();
|
||||
return null;
|
||||
|
@ -274,7 +274,7 @@ export function main() {
|
||||
var tcb: TestComponentBuilder;
|
||||
|
||||
function createCompFixture(template: string, tcb: TestComponentBuilder,
|
||||
comp: Type = null): ComponentFixture {
|
||||
comp: Type = null): ComponentFixture<any> {
|
||||
if (isBlank(comp)) {
|
||||
comp = TestComp;
|
||||
}
|
||||
|
Reference in New Issue
Block a user