【发布时间】:2018-10-12 15:29:46
【问题描述】:
我有简单的组件
@Component({
selector: 'app-certificate-panel',
templateUrl: './certificate.component.html'
})
export class CertificateComponent {
@Input()
public certificate: Certificate;
}
带模板
<h3 translate>General</h3>
<x-form-row label="{{'Version' | translate}}">
{{ certificate.version }}
</x-form-row>
<x-form-row label="{{'Serial Number' | translate}}">
{{ certificate.serialNumber }}
</x-form-row>
<h3 translate>Issued From</h3>
<x-form-row label="{{'Common Name (CN)' | translate}}" *ngIf="certificate.issuedFrom.commonName">
{{ certificate.issuedFrom.commonName }}
</x-form-row>
<x-form-row label="{{'Organization Unit (OU)' | translate}}" *ngIf="certificate.issuedFrom.organizationUnit">
{{ certificate.issuedFrom.organizationUnit }}
</x-form-row>
显示了更多属性。这个模板中有几个*ngIf。
现在我想编写单元测试。我应该测试每个*ngIf 吗?不是在测试框架功能吗?
【问题讨论】:
-
*ngIf的输入来自哪里? -
我个人会对这段代码进行单元测试。模板层中的单元测试简单 ifs (ngIfs) 没有真正的收获。我通常从我的组件/服务/等中保留单元测试...而不是模板,并且模板逻辑是 e2e 测试中的测试。
-
@Aravind 它是在父组件中设置的
@Input。
标签: angular unit-testing typescript angular-test