Angular 5 service failing to pass unit tests with (NullInjectorError: No provider for HttpClient!)

前端 未结 3 697
予麋鹿
予麋鹿 2021-01-31 14:18

I keep getting the following errors when running unit tests

Error: StaticInjectorError(DynamicTestModule)[ApiService -> HttpClient]: 
      StaticInjectorErro         


        
3条回答
  •  攒了一身酷
    2021-01-31 14:49

    simply add it like this,

      beforeEach(() => {
        TestBed.configureTestingModule({
          imports: [
            HttpClientModule,
          ],
        }).compileComponents();
      });
    

提交回复
热议问题