【发布时间】:2021-01-04 09:25:59
【问题描述】:
我已经开始为 Angular 编写测试用例,在阅读互联网上的文章时,我发现有不同的方式可以配置我们的 TestBed。下面是几个例子:
示例 1:
beforeEach(async(() => {
TestBed.configureTestingModule({
...
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
}));
示例 2:
beforeEach(async(() => {
TestBed.configureTestingModule({
...
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例 3:
beforeEach(async(() => {
TestBed.configureTestingModule({
...
}).compileComponents();
fixture = TestBed.createComponent(Component);
component = fixture.componentInstance;
fixture.detectChanges();
}));
示例 4:
beforeEach(async() => {
TestBed.configureTestingModule({
...
});
await TestBed.compileComponents();
fixture = TestBed.createComponent(Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
我需要帮助了解推荐的方法是什么?
【问题讨论】: