NullInjectorError: No provider for HttpClient , throws error even in http client is injected
NullInjectorError: No provider for HttpClient , throws error even in http client is injected
import { HttpClientModule } from '@angular/common/http';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Routes } from '@angular/router';
import { DrawerService} from '../services/create-work-order-confirmation-drawer.service';
import { HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import { ConfirmationDrawerComponent } from './create-work-order-confirmation-drawer.component';
import { FormsModule } from '@angular/forms';
describe('ConfirmationDrawerComponent ', () => {
let component: ConfirmationDrawerComponent ;
let fixture: ComponentFixture<ConfirmationDrawerComponent >;
let CreateServices = DrawerService;
beforeEach(async (() => {
TestBed.configureTestingModule({
declarations: [ ConfirmationDrawerComponent ],
imports: [FormsModule, HttpClientTestingModule,RouterModule.forRoot([])],
providers: [{
provide: DrawerService
}],
schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ConfirmationDrawerComponent );
component = fixture.componentInstance;
CreateServices = TestBed.get(DrawerService);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
不确定是什么问题!
我错过了什么?
我已将所有模块添加到导入中,是否遗漏了什么?
导入:[FormsModule, HttpClientTestingModule,RouterModule.forRoot([])],
错误来自 CreateWorkOrderConfirmationDrawerService
的规范文件,转到该文件并检查是否导入了 HttpClientTestingModule
import { HttpClientModule } from '@angular/common/http';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Routes } from '@angular/router';
import { DrawerService} from '../services/create-work-order-confirmation-drawer.service';
import { HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import { ConfirmationDrawerComponent } from './create-work-order-confirmation-drawer.component';
import { FormsModule } from '@angular/forms';
describe('ConfirmationDrawerComponent ', () => {
let component: ConfirmationDrawerComponent ;
let fixture: ComponentFixture<ConfirmationDrawerComponent >;
let CreateServices = DrawerService;
beforeEach(async (() => {
TestBed.configureTestingModule({
declarations: [ ConfirmationDrawerComponent ],
imports: [FormsModule, HttpClientTestingModule,RouterModule.forRoot([])],
providers: [{
provide: DrawerService
}],
schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ConfirmationDrawerComponent );
component = fixture.componentInstance;
CreateServices = TestBed.get(DrawerService);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
不确定是什么问题!
我错过了什么?
我已将所有模块添加到导入中,是否遗漏了什么?
错误来自 CreateWorkOrderConfirmationDrawerService
的规范文件,转到该文件并检查是否导入了 HttpClientTestingModule