【问题标题】:Angular 2 spec test for a component using material design使用材料设计对组件进行 Angular 2 规范测试
【发布时间】:2016-12-07 00:16:56
【问题描述】:

我想测试一个使用材料设计并有标题的组件。

<md-card-title>{{title}}</md-card-title>

如何查询包含标题的元素?

it('should display original title', () => {

    // trigger change detection to update the view
    fixture.detectChanges();

    // query for the title by what ???
    de = fixture.debugElement.query(By ???('md-card-title'));

    // confirm the element's content
    expect(de.nativeElement.textContent).toContain(comp.title);
});

【问题讨论】:

    标签: angular testing material-design


    【解决方案1】:

    我认为您可以使用以下方法之一:

    import { MdCardTitle } from '@angular/material';
    
    de = fixture.debugElement.query(By.directive(MdCardTitle));
    

    de = fixture.debugElement.query(By.css('md-card-title'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 2019-07-08
      • 2018-03-19
      • 2017-01-23
      • 2017-11-24
      • 2017-05-02
      • 2016-08-24
      相关资源
      最近更新 更多