【发布时间】:2020-08-09 22:07:56
【问题描述】:
我在我的app-component.spec.ts 的每个describe 部分中编写了很多锅炉和重复代码。有没有办法减少它?另一个问题是,每当我写一个新的component 时,我必须在每个describe 中显式地添加对新component 的引用。例如。
describe('AppComponent Test suite', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach((() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
... //29 components need to be referrred her
],
imports: [
AppRoutingModule,
QuillModule,
BrowserModule,
HttpClientModule,
MatProgressBarModule,
BrowserAnimationsModule,
HttpClientXsrfModule.withOptions({cookieName: 'CJCsrfCookie', headerName: 'CJCsrfHeader'}),
ReactiveFormsModule
],
providers: [{provide: APP_BASE_HREF, useValue: '/'},
...//14 services need to be added here
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fit('should create the app', (async() => {
expect(component).toBeTruthy();
}));
...
});
如果我写另一个describe,我将不得不再次写所有imports 和declarations。我可以避免这种情况吗?
【问题讨论】:
标签: angular6 angular-test