测试时是否可以在不使用@ViewChild的情况下获取对局部变量的引用?

时间:2019-02-04 17:38:50

标签: angular unit-testing local-variables ng-template

我不认为添加@ViewChild('greatTemplate) ref;是一个好的解决方案,只是为了满足测试要求。必须有一种方法可以通过TestBed获得local variable引用。

<button (click)="doSomething(greatTemplate)>

<ng-template #greatTemplate>Hello, World.</ng-template>

我唯一能通过angular.io文档找到的是here in this section "debugelement",它解释了您可以挖掘夹具的debugElement引用来寻找local variables,但这似乎只能捕获组件或本机DOM元素,而不是ng-template

0 个答案:

没有答案