我在describe
的每个app-component.spec.ts
部分中编写了很多锅炉代码和重复代码。有办法减少吗?另一个问题是,每当我编写一个新的component
时,都必须在每个component
中显式地添加对新describe
的引用。例如。
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
。我可以避免吗?
我在我的app-component.spec.ts的每个describe部分中编写了很多锅炉代码和重复代码。有办法减少吗?另一个问题是,每当我编写新组件时,都必须...
除非我弄错,否则似乎很容易做到!