Unit test for Component within component Angular 4 -
i using tab control using thoughtram blog post. here plnkr same.
i trying create unit test cases tabs component internally using tab component. , not sure how can in angular 4 jasmine.
how can inject tab in tabs component cover ngaftercontentinit() , selecttab() methods?
thanks..
i unit test tabs wrapping test component , run assertion on that, below:
@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(); }); }); hope help!
Comments
Post a Comment