小编Vij*_*ati的帖子

角度:7 如何测试父组件上的子发射器?

为事件发射器编写测试用例。modelopen()为方法编写测试用例

父ts文件author-article-carousel.component.ts

public edit(row) {
    console.log(row);
    this.activeArticleService.getArticleDetail(row.id).subscribe((res: any) => {
      this.modalOpen(res);
    });
  }


  public modalOpen(value) {
    let config = {};
    config = {
      disableClose: true,
      maxWidth: '1050px',
      data: { value: value, user: 'author' }
    };
    if (this.dialogRef == null) {
      this.dialogRef = this.dialog.open(ArticleModalComponent, config);
    }
    this.dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog closed: ${result}`);
      this.dialogRef = null;
    });

    this.dialogRef.componentInstance.downloadreport.subscribe(response => {
      if (response) {
        this.activeArticleService.downloadReport(response).subscribe((response: HttpResponse<Blob>) => {
          this.activeArticleService.download(response, 'report.pdf');
        });
      }
    });
}
Run Code Online (Sandbox Code Playgroud)

父 HTML 文件author-article-carousel.component.html

<prism-article-carousel
  (clickOnTitle)="edit($event)"
></prism-article-carousel>
Run Code Online (Sandbox Code Playgroud)

子 …

javascript typescript angular

5
推荐指数
1
解决办法
3267
查看次数

标签 统计

angular ×1

javascript ×1

typescript ×1