describe('ComponentHttpRServiceComponent', () => {
let component: ComponentHttpRServiceComponent;
let fixture: ComponentFixture<ComponentHttpRServiceComponent>;
let service: StudentService;
let httpclient: HttpClient;
// let httptestcontroller: HttpTestingController; <--
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ComponentHttpRServiceComponent],
imports: [HttpClientTestingModule],// HttpTestingController <--
providers: [StudentService],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ComponentHttpRServiceComponent);
component = fixture.componentInstance;
fixture.detectChanges();
service = TestBed.inject(StudentService);
// httptestcontroller = TestBed.inject(HttpTestingController); <--
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('httpclient get method', () => {});
});
每當我在匯入陣列中添加 HttpTestingController 時,我都會收到一個錯誤,該錯誤被寫入模塊“DynamicTestModule”匯入的意外值“HttpTestingController”。請添加 @NgModule 注釋。
如何解決上述問題?
uj5u.com熱心網友回復:
您不需要添加HttpTestingController任何地方,imports也不providers需要添加,您只需要添加您已經添加HttpClientTestingModule的內容。imports
HttpTestingController是的一部分HttpClientTestingModule,所以你會HttpTestingController在下面的行中得到,只需取消注釋它就可以了。
httptestcontroller = TestBed.inject(HttpTestingController);
這是完整的配置
//*Removed extra code for readability
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
}).compileComponents();
});
beforeEach(() => {
httptestcontroller = TestBed.inject(HttpTestingController);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/515041.html
上一篇:在路由中模擬索引函式內的物件
