test(query): add a test for view query with var bindings

Closes #3920

Closes #3946
This commit is contained in:
Rado Kirov 2015-09-01 15:26:46 -07:00 committed by Rado Kirov
parent 01cdd31339
commit 5c9613e084
1 changed files with 27 additions and 0 deletions

View File

@ -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 = '<needs-view-query-by-var-binding #q></needs-view-query-by-var-binding>';
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: '<div #text-label>text</div>'})
@Injectable()
class NeedsViewQueryByLabel {
query: QueryList<any>;
constructor(@ViewQuery("textLabel", {descendants: true}) query: QueryList<any>) {
this.query = query;
}
}
@Component({selector: 'needs-query-by-var-bindings'})
@View({directives: [], template: '<ng-content>'})
@Injectable()
@ -665,6 +691,7 @@ class NeedsTpl {
NeedsViewQueryIf,
NeedsViewQueryNestedIf,
NeedsViewQueryOrder,
NeedsViewQueryByLabel,
NeedsTpl,
TextDirective,
InertDirective,