From 5c9613e0845c91920af2cbe6ed24ad6c3f9b6848 Mon Sep 17 00:00:00 2001 From: Rado Kirov Date: Tue, 1 Sep 2015 15:26:46 -0700 Subject: [PATCH] test(query): add a test for view query with var bindings Closes #3920 Closes #3946 --- .../core/compiler/query_integration_spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/modules/angular2/test/core/compiler/query_integration_spec.ts b/modules/angular2/test/core/compiler/query_integration_spec.ts index 63920aabe0..255ad25331 100644 --- a/modules/angular2/test/core/compiler/query_integration_spec.ts +++ b/modules/angular2/test/core/compiler/query_integration_spec.ts @@ -349,6 +349,22 @@ export function main() { expect(asNativeElements(view.componentViewChildren)).toHaveText('hello|world|'); + async.done(); + }); + })); + + it('should support querying the view by using a view query', + inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { + var template = ''; + + tcb.overrideTemplate(MyComp, template) + .createAsync(MyComp) + .then((view) => { + var q: NeedsViewQueryByLabel = view.componentViewChildren[0].getLocal("q"); + view.detectChanges(); + + expect(q.query.first.nativeElement).toHaveText("text"); + async.done(); }); })); @@ -545,6 +561,16 @@ class NeedsQueryByLabel { } } +@Component({selector: 'needs-view-query-by-var-binding'}) +@View({directives: [], template: '
text
'}) +@Injectable() +class NeedsViewQueryByLabel { + query: QueryList; + constructor(@ViewQuery("textLabel", {descendants: true}) query: QueryList) { + this.query = query; + } +} + @Component({selector: 'needs-query-by-var-bindings'}) @View({directives: [], template: ''}) @Injectable() @@ -665,6 +691,7 @@ class NeedsTpl { NeedsViewQueryIf, NeedsViewQueryNestedIf, NeedsViewQueryOrder, + NeedsViewQueryByLabel, NeedsTpl, TextDirective, InertDirective,