私は以下のように、その上のテストコンポーネントと実行アサーションにラッピングすることにより、ユニットテストtabs
でしょう:
@Component({
template: `
<tabs>
<tab title="tab-1"></tab>
<tab title="tab-2"></tab>
</tabs>`,
})
class TestTabsComponent { }
describe("Component: Tabs",() => {
let component: TestTabsComponent;
let fixture: ComponentFixture<TestTabsComponent>;
beforeEach(() => {
TestBed
.configureTestingModule({
declarations: [
TabsComponent,
TabComponent,
TestTabsComponent,
],
});
fixture = TestBed.createComponent(TestTabsComponent);
component = fixture.componentInstance;
});
it('should have tab title', async(() => {
fixture.detectChanges();
let compiled = fixture.debugElement.queryAll(By.css('tab'));
expect(compiled[0].nativeElement.title).toBe('tab-1');
expect(compiled[1].nativeElement.title).toBe('tab-2');
}));
afterEach(() => {
fixture.destroy();
});
});
はそれが役立つだろう願っています!
このスレッドが役立つかどうかわかりません。私に知らせてください.https://stackoverflow.com/questions/35975879/angular2-test-how-do-i-mock-sub-component – JGFMK
あなたは 'Tab'コンポーネントを別途テストしているわけではありません'タブ'コンポーネント?私はそれがより良いオプションになると思う。 – 0mpurdy
'Tabs'コンポーネントをテストするために、' Tab'コレクションも渡す必要があります。それが私の質問だった。私はそれを 'Tabs'コンポーネントに渡すことができます。 – user7890278