我有一个组件。他的主要作用是包装。Angular 2测试
有什么麻烦?
方法compileComponents执行组件没有属性标题。这就是为什么,因为我认为,在控制台我看到错误
问题是:如何我可以先绑定属性,然后运行compileComponents方法?
组件模板:
<div class="card">
<div *ngIf="title" class="card-header clearfix">
<h3 class="card-title">{{ title }}</h3>
</div>
<div class="card-body">
<ng-content></ng-content>
</div>
</div>
说明部分:
describe('CardComponent',() => {
let comp: CardComponent;
let fixture: ComponentFixture<CardComponent>;
let titleEl: DebugElement; // the DebugElement with the welcome message
// async beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CardComponent ],
}).compileComponents(); // compile template and css
}));
// synchronous beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(CardComponent);
comp = fixture.componentInstance;
titleEl = fixture.debugElement.query(By.css('.card-title'));
comp.title = "Greatest title";
fixture.detectChanges(); // trigger initial data binding
});
it('Card check title',() => {
expect(titleEl.nativeElement.textContent).toContain("Greatest title");
});
});
你可以给[mcve]包括你的组件和错误*作为文本*? – jonrsharpe