test(query): add a test for view query with var bindings
Closes #3920 Closes #3946
This commit is contained in:
parent
01cdd31339
commit
5c9613e084
@ -349,6 +349,22 @@ export function main() {
|
|||||||
|
|
||||||
expect(asNativeElements(view.componentViewChildren)).toHaveText('hello|world|');
|
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();
|
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'})
|
@Component({selector: 'needs-query-by-var-bindings'})
|
||||||
@View({directives: [], template: '<ng-content>'})
|
@View({directives: [], template: '<ng-content>'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -665,6 +691,7 @@ class NeedsTpl {
|
|||||||
NeedsViewQueryIf,
|
NeedsViewQueryIf,
|
||||||
NeedsViewQueryNestedIf,
|
NeedsViewQueryNestedIf,
|
||||||
NeedsViewQueryOrder,
|
NeedsViewQueryOrder,
|
||||||
|
NeedsViewQueryByLabel,
|
||||||
NeedsTpl,
|
NeedsTpl,
|
||||||
TextDirective,
|
TextDirective,
|
||||||
InertDirective,
|
InertDirective,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user