Angular 组件角度4内组件的单元测试
我正在使用标签控件使用博客文章。这是同样的理由 我试图为Tabs组件创建一个单元测试用例,它在内部使用Tab组件。我不知道如何在Angular 组件角度4内组件的单元测试,angular,unit-testing,jasmine,Angular,Unit Testing,Jasmine,我正在使用标签控件使用博客文章。这是同样的理由 我试图为Tabs组件创建一个单元测试用例,它在内部使用Tab组件。我不知道如何在angular4中使用Jasmine来实现它 如何在Tabs组件中插入Tab,以便覆盖其ngAfterContentInit()和selectTab()方法 谢谢..我会将选项卡封装到一个测试组件中进行单元测试,并对其运行断言,如下所示: @Component({ template: ` <tabs> <tab title="tab
angular4
中使用Jasmine
来实现它
如何在Tabs组件中插入Tab,以便覆盖其ngAfterContentInit()
和selectTab()
方法
谢谢..我会将
选项卡封装到一个测试组件中进行单元测试,并对其运行断言,如下所示:
@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();
});
});
@组件({
模板:`
`,
})
类TestTabsComponent{}
描述(“组件:选项卡”,()=>{
let组件:TestTabsComponent;
let夹具:组件夹具;
在每个之前(()=>{
试验台
.配置测试模块({
声明:[
选项卡组件,
选项卡组件,
TestTabsComponent,
],
});
fixture=TestBed.createComponent(TestTabsComponent);
组件=fixture.componentInstance;
});
它('应该有选项卡标题',异步(()=>{
fixture.detectChanges();
让compiled=fixture.debugElement.queryAll(By.css('tab');
expect(已编译[0].nativeElement.title).toBe('tab-1');
expect(已编译[1].nativeElement.title).toBe('tab-2');
}));
之后(()=>{
fixture.destroy();
});
});
希望能有帮助 我不知道这条线是否有用。让我知道..是否有理由不将选项卡
组件与选项卡
组件分开测试?我认为这是一个更好的选择为了测试Tabs
组件,您还必须通过Tab
集合。这就是我的问题所在;如何将其传递到选项卡
组件。谢谢。。在这之后我得到了100%的保险。