Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions packages/common/test/directives/ng_component_outlet_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {NgComponentOutlet} from '@angular/common/src/directives/ng_component_out
import {Compiler, Component, ComponentRef, Inject, InjectionToken, Injector, NO_ERRORS_SCHEMA, NgModule, NgModuleFactory, Optional, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {modifiedInIvy} from '@angular/private/testing';

describe('insert/remove', () => {

Expand Down Expand Up @@ -108,19 +107,18 @@ describe('insert/remove', () => {
}));


modifiedInIvy('Static ViewChild and ContentChild queries are resolved in update mode')
.it('should resolve with an injector', async(() => {
let fixture = TestBed.createComponent(TestComponent);
it('should resolve with an injector', async(() => {
let fixture = TestBed.createComponent(TestComponent);

// We are accessing a ViewChild (ngComponentOutlet) before change detection has run
fixture.componentInstance.cmpRef = null;
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef !;
expect(cmpRef).toBeAnInstanceOf(ComponentRef);
expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent);
expect(cmpRef.instance.testToken).toBeNull();
}));
// We are accessing a ViewChild (ngComponentOutlet) before change detection has run
fixture.componentInstance.cmpRef = null;
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef !;
expect(cmpRef).toBeAnInstanceOf(ComponentRef);
expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent);
expect(cmpRef.instance.testToken).toBeNull();
}));

it('should render projectable nodes, if supplied', async(() => {
const template = `<ng-template>projected foo</ng-template>${TEST_CMP_TEMPLATE}`;
Expand Down Expand Up @@ -240,7 +238,7 @@ class TestComponent {
// TODO(issue/24571): remove '!'.
@ViewChildren(TemplateRef) tplRefs !: QueryList<TemplateRef<any>>;
// TODO(issue/24571): remove '!'.
@ViewChild(NgComponentOutlet) ngComponentOutlet !: NgComponentOutlet;
@ViewChild(NgComponentOutlet, {static: true}) ngComponentOutlet !: NgComponentOutlet;

constructor(public vcRef: ViewContainerRef) {}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/common/test/directives/ng_switch_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ class TestComponent {
`
})
class ComplexComponent {
@ViewChild('foo') foo !: TemplateRef<any>;
@ViewChild('bar') bar !: TemplateRef<any>;
@ViewChild('foo', {static: true}) foo !: TemplateRef<any>;
@ViewChild('bar', {static: true}) bar !: TemplateRef<any>;
state: string = 'case1';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@ContentChild(SomeDirective) someDir: SomeDirective;
@ContentChild(SomeDirective, {static: false}) someDir: SomeDirective;
@ContentChildren(SomeDirective) someDirList !: QueryList<SomeDirective>;
}

Expand Down Expand Up @@ -1786,7 +1786,7 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@ContentChild('myRef') myRef: any;
@ContentChild('myRef', {static: false}) myRef: any;
@ContentChildren('myRef1, myRef2, myRef3') myRefs: QueryList<any>;
}
@NgModule({declarations: [ContentQueryComponent]})
Expand Down Expand Up @@ -1911,9 +1911,9 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@ContentChild('myRef', {read: TemplateRef}) myRef: TemplateRef;
@ContentChild('myRef', {read: TemplateRef, static: false}) myRef: TemplateRef;
@ContentChildren('myRef1, myRef2, myRef3', {read: ElementRef}) myRefs: QueryList<ElementRef>;
@ContentChild(SomeDirective, {read: ElementRef}) someDir: ElementRef;
@ContentChild(SomeDirective, {read: ElementRef, static: false}) someDir: ElementRef;
@ContentChildren(SomeDirective, {read: TemplateRef}) someDirs: QueryList<TemplateRef>;
}
@NgModule({declarations: [ContentQueryComponent]})
Expand Down Expand Up @@ -1966,7 +1966,7 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@Input() @ContentChild('foo') foo: any;
@Input() @ContentChild('foo', {static: false}) foo: any;
}

@Component({
Expand Down Expand Up @@ -3139,7 +3139,7 @@ describe('compiler compliance', () => {
'spec.ts': `
import {Component, NgModule, ContentChild} from '@angular/core';
export class BaseClass {
@ContentChild('something') something: any;
@ContentChild('something', {static: false}) something: any;
}

@Component({
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,10 +1536,10 @@ describe('ngtsc behavioral tests', () => {
}
})
class FooCmp {
@ContentChild('bar', {read: TemplateRef}) child: any;
@ContentChild('bar', {read: TemplateRef, static: false}) child: any;
@ContentChildren(TemplateRef) children: any;
get aview(): any { return null; }
@ViewChild('accessor') set aview(value: any) {}
@ViewChild('accessor', {static: false}) set aview(value: any) {}
}
`);

Expand Down Expand Up @@ -1568,7 +1568,7 @@ describe('ngtsc behavioral tests', () => {
}
})
class FooCmp {
@ContentChild('bar', {read: TemplateRef}) child: any;
@ContentChild('bar', {read: TemplateRef, static: false}) child: any;
@ContentChildren(TemplateRef) children: any;
get aview(): any { return null; }
@ViewChild('accessor') set aview(value: any) {}
Expand Down Expand Up @@ -1600,11 +1600,11 @@ describe('ngtsc behavioral tests', () => {
template: '<div #foo></div>',
})
class FooCmp {
@ContentChild(forwardRef(() => TemplateRef)) child: any;
@ContentChild(forwardRef(() => TemplateRef), {static: false}) child: any;

@ContentChild(forwardRef(function() { return ViewContainerRef; })) child2: any;
@ContentChild(forwardRef(function() { return ViewContainerRef; }), {static: false}) child2: any;

@ContentChild((forwardRef((function() { return 'parens'; }) as any))) childInParens: any;
@ContentChild((forwardRef((function() { return 'parens'; }) as any)), {static: false}) childInParens: any;
}
`);

Expand Down
14 changes: 8 additions & 6 deletions packages/compiler/test/core_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import * as core from '@angular/core';
typeExtends<compilerCore.Query, core.Query>();
typeExtends<core.Query, compilerCore.Query>();
compareRuntimeShape(
new core.ContentChild('someSelector'), compilerCore.createContentChild('someSelector'));
new core.ContentChild('someSelector', {static: false}),
compilerCore.createContentChild('someSelector', {static: false}));
compareRuntimeShape(
new core.ContentChild('someSelector', {read: 'someRead'}),
compilerCore.createContentChild('someSelector', {read: 'someRead'}));
new core.ContentChild('someSelector', {read: 'someRead', static: false}),
compilerCore.createContentChild('someSelector', {read: 'someRead', static: false}));
compareRuntimeShape(
new core.ContentChildren('someSelector'),
compilerCore.createContentChildren('someSelector'));
Expand All @@ -39,10 +40,11 @@ import * as core from '@angular/core';
compilerCore.createContentChildren(
'someSelector', {read: 'someRead', descendants: false}));
compareRuntimeShape(
new core.ViewChild('someSelector'), compilerCore.createViewChild('someSelector'));
new core.ViewChild('someSelector', {static: false}),
compilerCore.createViewChild('someSelector', {static: false}));
compareRuntimeShape(
new core.ViewChild('someSelector', {read: 'someRead'}),
compilerCore.createViewChild('someSelector', {read: 'someRead'}));
new core.ViewChild('someSelector', {read: 'someRead', static: false}),
compilerCore.createViewChild('someSelector', {read: 'someRead', static: false}));
compareRuntimeShape(
new core.ViewChildren('someSelector'), compilerCore.createViewChildren('someSelector'));
compareRuntimeShape(
Expand Down
34 changes: 19 additions & 15 deletions packages/compiler/test/directive_resolver_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class SomeDirectiveWithViewChildren {
c: any;
}

@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c')}})
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c', {static: false})}})
class SomeDirectiveWithContentChild {
@ContentChild('a') a: any;
@ContentChild('a', {static: false}) a: any;
c: any;
}

@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c')}})
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c', {static: false})}})
class SomeDirectiveWithViewChild {
@ViewChild('a') a: any;
@ViewChild('a', {static: false}) a: any;
c: any;
}

Expand Down Expand Up @@ -408,37 +408,41 @@ class SomeDirectiveWithoutMetadata {}

it('should append ContentChild', () => {
const directiveMetadata = resolver.resolve(SomeDirectiveWithContentChild);
expect(directiveMetadata.queries)
.toEqual({'c': new ContentChild('c'), 'a': new ContentChild('a')});
expect(directiveMetadata.queries).toEqual({
'c': new ContentChild('c', {static: false}),
'a': new ContentChild('a', {static: false})
});
});

it('should append ViewChild', () => {
const directiveMetadata = resolver.resolve(SomeDirectiveWithViewChild);
expect(directiveMetadata.queries)
.toEqual({'c': new ViewChild('c'), 'a': new ViewChild('a')});
expect(directiveMetadata.queries).toEqual({
'c': new ViewChild('c', {static: false}),
'a': new ViewChild('a', {static: false})
});
});

it('should support inheriting queries', () => {
@Directive({selector: 'p'})
class Parent {
@ContentChild('p1')
@ContentChild('p1', {static: false})
p1: any;
@ContentChild('p21')
@ContentChild('p21', {static: false})
p2: any;
}

class Child extends Parent {
@ContentChild('p22')
@ContentChild('p22', {static: false})
p2: any;
@ContentChild('p3')
@ContentChild('p3', {static: false})
p3: any;
}

const directiveMetadata = resolver.resolve(Child);
expect(directiveMetadata.queries).toEqual({
'p1': new ContentChild('p1'),
'p2': new ContentChild('p22'),
'p3': new ContentChild('p3')
'p1': new ContentChild('p1', {static: false}),
'p2': new ContentChild('p22', {static: false}),
'p3': new ContentChild('p3', {static: false})
});
});
});
Expand Down
34 changes: 17 additions & 17 deletions packages/core/test/acceptance/change_detection_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('change detection', () => {
})
class TestCmpt {
counter = 0;
@ViewChild('vc', {read: ViewContainerRef}) vcRef !: ViewContainerRef;
@ViewChild('vc', {read: ViewContainerRef, static: false}) vcRef !: ViewContainerRef;

constructor(private _cfr: ComponentFactoryResolver) {}

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('change detection', () => {

@Component({selector: 'my-app', template: '<my-comp [name]="name"></my-comp>'})
class MyApp {
@ViewChild(MyComponent) comp !: MyComponent;
@ViewChild(MyComponent, {static: false}) comp !: MyComponent;
name: string = 'Nancy';
}

Expand Down Expand Up @@ -238,7 +238,7 @@ describe('change detection', () => {
template: '<my-comp></my-comp><button id="parent" (click)="noop()"></button>'
})
class ButtonParent {
@ViewChild(MyComponent) comp !: MyComponent;
@ViewChild(MyComponent, {static: false}) comp !: MyComponent;
noop() {}
}

Expand All @@ -264,7 +264,7 @@ describe('change detection', () => {
changeDetection: ChangeDetectionStrategy.OnPush
})
class ButtonParent implements DoCheck {
@ViewChild(MyComponent) comp !: MyComponent;
@ViewChild(MyComponent, {static: false}) comp !: MyComponent;
noop() {}

doCheckCount = 0;
Expand All @@ -273,7 +273,7 @@ describe('change detection', () => {

@Component({selector: 'my-button-app', template: '<button-parent></button-parent>'})
class MyButtonApp {
@ViewChild(ButtonParent) parent !: ButtonParent;
@ViewChild(ButtonParent, {static: false}) parent !: ButtonParent;
}

TestBed.configureTestingModule({declarations: [MyButtonApp, MyComponent, ButtonParent]});
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('change detection', () => {

@Component({selector: 'parent-comp', template: `{{ doCheckCount}} - <my-comp></my-comp>`})
class ParentComp implements DoCheck {
@ViewChild(MyComp) myComp !: MyComp;
@ViewChild(MyComp, {static: false}) myComp !: MyComp;

doCheckCount = 0;

Expand Down Expand Up @@ -411,8 +411,8 @@ describe('change detection', () => {
it('should check component view when called by directive on component node', () => {
@Component({template: '<my-comp dir></my-comp>'})
class MyApp {
@ViewChild(MyComp) myComp !: MyComp;
@ViewChild(Dir) dir !: Dir;
@ViewChild(MyComp, {static: false}) myComp !: MyComp;
@ViewChild(Dir, {static: false}) dir !: Dir;
}

TestBed.configureTestingModule({declarations: [MyComp, Dir, MyApp]});
Expand All @@ -429,8 +429,8 @@ describe('change detection', () => {
it('should check host component when called by directive on element node', () => {
@Component({template: '{{ value }}<div dir></div>'})
class MyApp {
@ViewChild(MyComp) myComp !: MyComp;
@ViewChild(Dir) dir !: Dir;
@ViewChild(MyComp, {static: false}) myComp !: MyComp;
@ViewChild(Dir, {static: false}) dir !: Dir;
value = '';
}

Expand All @@ -450,7 +450,7 @@ describe('change detection', () => {
it('should check the host component when called from EmbeddedViewRef', () => {
@Component({template: '{{ name }}<div *ngIf="showing" dir></div>'})
class MyApp {
@ViewChild(Dir) dir !: Dir;
@ViewChild(Dir, {static: false}) dir !: Dir;
showing = true;
name = 'Amelia';
}
Expand Down Expand Up @@ -563,7 +563,7 @@ describe('change detection', () => {
'<ng-template #foo let-ctx="ctx">{{ ctx.value }}</ng-template><structural-comp [tmp]="foo"></structural-comp>'
})
class App {
@ViewChild(StructuralComp) structuralComp !: StructuralComp;
@ViewChild(StructuralComp, {static: false}) structuralComp !: StructuralComp;
}

TestBed.configureTestingModule({declarations: [App, StructuralComp]});
Expand Down Expand Up @@ -592,7 +592,7 @@ describe('change detection', () => {
template: '<ng-template #foo>Template text</ng-template><structural-comp [tmp]="foo">'
})
class App {
@ViewChild(StructuralComp) structuralComp !: StructuralComp;
@ViewChild(StructuralComp, {static: false}) structuralComp !: StructuralComp;
}

TestBed.configureTestingModule({declarations: [App, StructuralComp]});
Expand Down Expand Up @@ -623,7 +623,7 @@ describe('change detection', () => {

@Component({template: '<detached-comp></detached-comp>'})
class MyApp {
@ViewChild(DetachedComp) comp !: DetachedComp;
@ViewChild(DetachedComp, {static: false}) comp !: DetachedComp;

constructor(public cdr: ChangeDetectorRef) {}
}
Expand Down Expand Up @@ -734,7 +734,7 @@ describe('change detection', () => {

@Component({template: '<on-push-comp [value]="value"></on-push-comp>'})
class OnPushApp {
@ViewChild(OnPushComp) onPushComp !: OnPushComp;
@ViewChild(OnPushComp, {static: false}) onPushComp !: OnPushComp;
value = '';
}

Expand Down Expand Up @@ -781,7 +781,7 @@ describe('change detection', () => {
changeDetection: ChangeDetectionStrategy.OnPush
})
class OnPushParent {
@ViewChild(OnPushComp) comp !: OnPushComp;
@ViewChild(OnPushComp, {static: false}) comp !: OnPushComp;
value = 'one';
}

Expand Down Expand Up @@ -843,7 +843,7 @@ describe('change detection', () => {
changeDetection: ChangeDetectionStrategy.OnPush
})
class EmbeddedViewParent {
@ViewChild(OnPushComp) comp !: OnPushComp;
@ViewChild(OnPushComp, {static: false}) comp !: OnPushComp;
value = 'one';
showing = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/acceptance/component_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('component', () => {
entryComponents: [OtherComponent]
})
class TestComponent {
@ViewChild('vc', {read: ViewContainerRef}) vcref !: ViewContainerRef;
@ViewChild('vc', {read: ViewContainerRef, static: true}) vcref !: ViewContainerRef;

constructor(private _cfr: ComponentFactoryResolver) {}

Expand Down
Loading