test(core): update query-specific tests in core (#30626)
PR Close #30626
This commit is contained in:
		
							parent
							
								
									214ae0ea4c
								
							
						
					
					
						commit
						faac51fd2e
					
				| @ -177,7 +177,7 @@ describe('query logic', () => { | ||||
| 
 | ||||
|     it('should support ViewChild query inherited from undecorated superclasses', () => { | ||||
|       class MyComp { | ||||
|         @ViewChild('foo') foo: any; | ||||
|         @ViewChild('foo', {static: false}) foo: any; | ||||
|       } | ||||
| 
 | ||||
|       @Component({selector: 'sub-comp', template: '<div #foo></div>'}) | ||||
| @ -193,7 +193,7 @@ describe('query logic', () => { | ||||
| 
 | ||||
|     it('should support ViewChild query inherited from undecorated grand superclasses', () => { | ||||
|       class MySuperComp { | ||||
|         @ViewChild('foo') foo: any; | ||||
|         @ViewChild('foo', {static: false}) foo: any; | ||||
|       } | ||||
| 
 | ||||
|       class MyComp extends MySuperComp {} | ||||
| @ -493,7 +493,7 @@ describe('query logic', () => { | ||||
| 
 | ||||
|     it('should support ContentChild query inherited from undecorated superclasses', () => { | ||||
|       class MyComp { | ||||
|         @ContentChild('foo') foo: any; | ||||
|         @ContentChild('foo', {static: false}) foo: any; | ||||
|       } | ||||
| 
 | ||||
|       @Component({selector: 'sub-comp', template: '<ng-content></ng-content>'}) | ||||
| @ -502,7 +502,7 @@ describe('query logic', () => { | ||||
| 
 | ||||
|       @Component({template: '<sub-comp><div #foo></div></sub-comp>'}) | ||||
|       class App { | ||||
|         @ViewChild(SubComp) subComp !: SubComp; | ||||
|         @ViewChild(SubComp, {static: false}) subComp !: SubComp; | ||||
|       } | ||||
| 
 | ||||
|       TestBed.configureTestingModule({declarations: [App, SubComp]}); | ||||
| @ -514,7 +514,7 @@ describe('query logic', () => { | ||||
| 
 | ||||
|     it('should support ContentChild query inherited from undecorated grand superclasses', () => { | ||||
|       class MySuperComp { | ||||
|         @ContentChild('foo') foo: any; | ||||
|         @ContentChild('foo', {static: false}) foo: any; | ||||
|       } | ||||
| 
 | ||||
|       class MyComp extends MySuperComp {} | ||||
| @ -525,7 +525,7 @@ describe('query logic', () => { | ||||
| 
 | ||||
|       @Component({template: '<sub-comp><div #foo></div></sub-comp>'}) | ||||
|       class App { | ||||
|         @ViewChild(SubComp) subComp !: SubComp; | ||||
|         @ViewChild(SubComp, {static: false}) subComp !: SubComp; | ||||
|       } | ||||
| 
 | ||||
|       TestBed.configureTestingModule({declarations: [App, SubComp]}); | ||||
| @ -557,7 +557,7 @@ describe('query logic', () => { | ||||
|       ` | ||||
|       }) | ||||
|       class App { | ||||
|         @ViewChild(SubComp) subComp !: SubComp; | ||||
|         @ViewChild(SubComp, {static: false}) subComp !: SubComp; | ||||
|       } | ||||
| 
 | ||||
|       TestBed.configureTestingModule({declarations: [App, SubComp, SomeDir]}); | ||||
| @ -592,7 +592,7 @@ describe('query logic', () => { | ||||
|       ` | ||||
|       }) | ||||
|       class App { | ||||
|         @ViewChild(SubComp) subComp !: SubComp; | ||||
|         @ViewChild(SubComp, {static: false}) subComp !: SubComp; | ||||
|       } | ||||
| 
 | ||||
|       TestBed.configureTestingModule({declarations: [App, SubComp, SomeDir]}); | ||||
| @ -806,9 +806,10 @@ describe('query logic', () => { | ||||
|              `,
 | ||||
|            }) | ||||
|            class TestComponent { | ||||
|              @ViewChild(ViewContainerManipulatorDirective) vc !: ViewContainerManipulatorDirective; | ||||
|              @ViewChild('tpl1') tpl1 !: TemplateRef<any>; | ||||
|              @ViewChild('tpl2') tpl2 !: TemplateRef<any>; | ||||
|              @ViewChild(ViewContainerManipulatorDirective, {static: false}) | ||||
|              vc !: ViewContainerManipulatorDirective; | ||||
|              @ViewChild('tpl1', {static: false}) tpl1 !: TemplateRef<any>; | ||||
|              @ViewChild('tpl2', {static: false}) tpl2 !: TemplateRef<any>; | ||||
|              @ViewChildren('foo') query !: QueryList<any>; | ||||
|            } | ||||
| 
 | ||||
| @ -878,9 +879,9 @@ describe('query logic', () => { | ||||
|              `,
 | ||||
|                 }) | ||||
|                 class TestComponent { | ||||
|                   @ViewChild('tpl') tpl !: TemplateRef<any>; | ||||
|                   @ViewChild('vi0') vi0 !: ViewContainerManipulatorDirective; | ||||
|                   @ViewChild('vi1') vi1 !: ViewContainerManipulatorDirective; | ||||
|                   @ViewChild('tpl', {static: false}) tpl !: TemplateRef<any>; | ||||
|                   @ViewChild('vi0', {static: false}) vi0 !: ViewContainerManipulatorDirective; | ||||
|                   @ViewChild('vi1', {static: false}) vi1 !: ViewContainerManipulatorDirective; | ||||
|                   @ViewChildren('foo') query !: QueryList<any>; | ||||
|                 } | ||||
| 
 | ||||
| @ -963,8 +964,8 @@ function initWithTemplate(compType: Type<any>, template: string) { | ||||
| 
 | ||||
| @Component({selector: 'local-ref-query-component', template: '<ng-content></ng-content>'}) | ||||
| class QueryComp { | ||||
|   @ViewChild('viewQuery') viewChild !: any; | ||||
|   @ContentChild('contentQuery') contentChild !: any; | ||||
|   @ViewChild('viewQuery', {static: false}) viewChild !: any; | ||||
|   @ContentChild('contentQuery', {static: false}) contentChild !: any; | ||||
| 
 | ||||
|   @ViewChildren('viewQuery') viewChildren !: QueryList<any>; | ||||
|   @ContentChildren('contentQuery') contentChildren !: QueryList<any>; | ||||
|  | ||||
| @ -752,7 +752,7 @@ describe('Query API', () => { | ||||
|               class AutoProjecting { | ||||
|                 // TODO(issue/24571):
 | ||||
|                 // remove '!'.
 | ||||
|                 @ContentChild(TemplateRef) | ||||
|                 @ContentChild(TemplateRef, {static: false}) | ||||
|                 content !: TemplateRef<any>; | ||||
| 
 | ||||
|                 // TODO(issue/24571):
 | ||||
| @ -784,7 +784,7 @@ describe('Query API', () => { | ||||
|            class AutoProjecting { | ||||
|              // TODO(issue/24571):
 | ||||
|              // remove '!'.
 | ||||
|              @ContentChild(TemplateRef) | ||||
|              @ContentChild(TemplateRef, {static: false}) | ||||
|              content !: TemplateRef<any>; | ||||
| 
 | ||||
|              // TODO(issue/24571):
 | ||||
| @ -839,7 +839,7 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   _child !: TextDirective; | ||||
| 
 | ||||
|   @ContentChild(TextDirective) | ||||
|   @ContentChild(TextDirective, {static: false}) | ||||
|   set child(value) { | ||||
|     this._child = value; | ||||
|     this.logs.push(['setter', value ? value.text : null]); | ||||
| @ -856,7 +856,7 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked { | ||||
| @Directive({selector: '[directive-needs-content-child]'}) | ||||
| class DirectiveNeedsContentChild { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TextDirective) child !: TextDirective; | ||||
|   @ContentChild(TextDirective, {static: false}) child !: TextDirective; | ||||
| } | ||||
| 
 | ||||
| @Component({selector: 'needs-view-child', template: `<div *ngIf="shouldShow" text="foo"></div>`}) | ||||
| @ -867,7 +867,7 @@ class NeedsViewChild implements AfterViewInit, AfterViewChecked { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   _child !: TextDirective; | ||||
| 
 | ||||
|   @ViewChild(TextDirective) | ||||
|   @ViewChild(TextDirective, {static: false}) | ||||
|   set child(value) { | ||||
|     this._child = value; | ||||
|     this.logs.push(['setter', value ? value.text : null]); | ||||
| @ -896,9 +896,9 @@ function createTestCmpAndDetectChanges<T>(type: Type<T>, template: string): Comp | ||||
| @Component({selector: 'needs-static-content-view-child', template: `<div text="viewFoo"></div>`}) | ||||
| class NeedsStaticContentAndViewChild { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TextDirective) contentChild !: TextDirective; | ||||
|   @ContentChild(TextDirective, {static: true}) contentChild !: TextDirective; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild(TextDirective) viewChild !: TextDirective; | ||||
|   @ViewChild(TextDirective, {static: true}) viewChild !: TextDirective; | ||||
| } | ||||
| 
 | ||||
| @Directive({selector: '[dir]'}) | ||||
| @ -917,13 +917,13 @@ class NeedsQuery { | ||||
| @Component({selector: 'needs-four-queries', template: ''}) | ||||
| class NeedsFourQueries { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TextDirective) query1 !: TextDirective; | ||||
|   @ContentChild(TextDirective, {static: false}) query1 !: TextDirective; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TextDirective) query2 !: TextDirective; | ||||
|   @ContentChild(TextDirective, {static: false}) query2 !: TextDirective; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TextDirective) query3 !: TextDirective; | ||||
|   @ContentChild(TextDirective, {static: false}) query3 !: TextDirective; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TextDirective) query4 !: TextDirective; | ||||
|   @ContentChild(TextDirective, {static: false}) query4 !: TextDirective; | ||||
| } | ||||
| 
 | ||||
| @Component({ | ||||
| @ -1025,9 +1025,9 @@ class NeedsTpl { | ||||
|     {selector: 'needs-named-tpl', template: '<ng-template #tpl><div>shadow</div></ng-template>'}) | ||||
| class NeedsNamedTpl { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('tpl') viewTpl !: TemplateRef<Object>; | ||||
|   @ViewChild('tpl', {static: true}) viewTpl !: TemplateRef<Object>; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild('tpl') contentTpl !: TemplateRef<Object>; | ||||
|   @ContentChild('tpl', {static: true}) contentTpl !: TemplateRef<Object>; | ||||
|   constructor(public vc: ViewContainerRef) {} | ||||
| } | ||||
| 
 | ||||
| @ -1042,9 +1042,10 @@ class NeedsContentChildrenWithRead { | ||||
| @Component({selector: 'needs-content-child-read', template: ''}) | ||||
| class NeedsContentChildWithRead { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild('q', {read: TextDirective}) textDirChild !: TextDirective; | ||||
|   @ContentChild('q', {read: TextDirective, static: false}) textDirChild !: TextDirective; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild('nonExisting', {read: TextDirective}) nonExistingVar !: TextDirective; | ||||
|   @ContentChild('nonExisting', {read: TextDirective, static: false}) | ||||
|   nonExistingVar !: TextDirective; | ||||
| } | ||||
| 
 | ||||
| @Component({selector: 'needs-content-children-shallow', template: ''}) | ||||
| @ -1059,7 +1060,7 @@ class NeedsContentChildrenShallow { | ||||
| }) | ||||
| class NeedsContentChildTemplateRef { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TemplateRef) templateRef !: TemplateRef<any>; | ||||
|   @ContentChild(TemplateRef, {static: true}) templateRef !: TemplateRef<any>; | ||||
| } | ||||
| 
 | ||||
| @Component({ | ||||
| @ -1088,19 +1089,20 @@ class NeedsViewChildrenWithRead { | ||||
| }) | ||||
| class NeedsViewChildWithRead { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('q', {read: TextDirective}) textDirChild !: TextDirective; | ||||
|   @ViewChild('q', {read: TextDirective, static: false}) textDirChild !: TextDirective; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('nonExisting', {read: TextDirective}) nonExistingVar !: TextDirective; | ||||
|   @ViewChild('nonExisting', {read: TextDirective, static: false}) nonExistingVar !: TextDirective; | ||||
| } | ||||
| 
 | ||||
| @Component({selector: 'needs-viewcontainer-read', template: '<div #q></div>'}) | ||||
| class NeedsViewContainerWithRead { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('q', {read: ViewContainerRef}) vc !: ViewContainerRef; | ||||
|   @ViewChild('q', {read: ViewContainerRef, static: false}) vc !: ViewContainerRef; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('nonExisting', {read: ViewContainerRef}) nonExistingVar !: ViewContainerRef; | ||||
|   @ViewChild('nonExisting', {read: ViewContainerRef, static: false}) | ||||
|   nonExistingVar !: ViewContainerRef; | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TemplateRef) template !: TemplateRef<Object>; | ||||
|   @ContentChild(TemplateRef, {static: true}) template !: TemplateRef<Object>; | ||||
| 
 | ||||
|   createView() { this.vc.createEmbeddedView(this.template); } | ||||
| } | ||||
| @ -1123,10 +1125,10 @@ class MyCompBroken0 { | ||||
| @Component({selector: 'manual-projecting', template: '<div #vc></div>'}) | ||||
| class ManualProjecting { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ContentChild(TemplateRef) template !: TemplateRef<any>; | ||||
|   @ContentChild(TemplateRef, {static: true}) template !: TemplateRef<any>; | ||||
| 
 | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('vc', {read: ViewContainerRef}) | ||||
|   @ViewChild('vc', {read: ViewContainerRef, static: false}) | ||||
|   vc !: ViewContainerRef; | ||||
| 
 | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|  | ||||
| @ -83,13 +83,13 @@ class Simple { | ||||
| @Component({selector: 'view-child-type-selector', template: ''}) | ||||
| class ViewChildTypeSelectorComponent { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild(Simple) child !: Simple; | ||||
|   @ViewChild(Simple, {static: false}) child !: Simple; | ||||
| } | ||||
| 
 | ||||
| @Component({selector: 'view-child-string-selector', template: ''}) | ||||
| class ViewChildStringSelectorComponent { | ||||
|   // TODO(issue/24571): remove '!'.
 | ||||
|   @ViewChild('child') child !: ElementRef; | ||||
|   @ViewChild('child', {static: false}) child !: ElementRef; | ||||
| } | ||||
| 
 | ||||
| @Component({selector: 'view-children-type-selector', template: ''}) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user