📌  相关文章
📜  NullInjectorError: R3InjectorError(DynamicTestModule)[TaskService -> HttpClient -> HttpClient]: NullInjectorError: No provider for HttpClient! - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:50.445000             🧑  作者: Mango

代码示例1
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import {HttpClientModule} from '@angular/common/http';
import { myService } from './myservice';


describe('myService', () => {

      beforeEach(() => TestBed.configureTestingModule({
        imports: [HttpClientTestingModule], 
        providers: [myService]
      }));

       it('should be created', () => {
        const service: myService = TestBed.get(myService);
        expect(service).toBeTruthy();
       });

       it('should have getData function', () => {
        const service: myService = TestBed.get(myService);
        expect(service.getData).toBeTruthy();
       });

    });